actix-web/actix-http
Tao Guo 7dc772c96d fix(http): preserve manual Content-Length headers for HEAD requests per RFC 7230
Implements RFC 7230 Section 3.3.2 which allows servers to send Content-Length
headers in HEAD responses. This enables support for APIs like AWS S3 HeadObject
that require Content-Length headers even with empty response bodies.

Previously, manually set Content-Length headers on empty body responses were
being overridden by automatic "content-length: 0" headers. Now the encoder
checks for existing Content-Length headers before adding automatic ones.
2025-08-09 13:04:20 -07:00
..
benches perf: remove unnecessary allocation when writing http dates (#3261) 2024-02-07 03:47:30 +00:00
examples chore: address clippy lints 2025-05-09 20:21:02 +01:00
src fix(http): preserve manual Content-Length headers for HEAD requests per RFC 7230 2025-08-09 13:04:20 -07:00
tests build(deps): update derive_more requirement from 1 to 2 (#3571) 2025-02-10 01:27:56 +00:00
CHANGES.md chore(actix-http): prepare release 3.11.0 2025-05-10 06:18:25 +01:00
Cargo.toml chore(actix-http): prepare release 3.11.0 2025-05-10 06:18:25 +01:00
LICENSE-APACHE prepare release beta 4 (#1659) 2020-09-09 22:14:11 +01:00
LICENSE-MIT prepare release beta 4 (#1659) 2020-09-09 22:14:11 +01:00
README.md chore(actix-http): prepare release 3.11.0 2025-05-10 06:18:25 +01:00

README.md

actix-http

HTTP types and services for the Actix ecosystem.

crates.io Documentation Version MIT or Apache 2.0 licensed
dependency status Download Chat on Discord

Examples

use std::{env, io};

use actix_http::{HttpService, Response};
use actix_server::Server;
use futures_util::future;
use http::header::HeaderValue;
use tracing::info;

#[actix_rt::main]
async fn main() -> io::Result<()> {
    env::set_var("RUST_LOG", "hello_world=info");
    env_logger::init();

    Server::build()
        .bind("hello-world", "127.0.0.1:8080", || {
            HttpService::build()
                .client_timeout(1000)
                .client_disconnect(1000)
                .finish(|_req| {
                    info!("{:?}", _req);
                    let mut res = Response::Ok();
                    res.header("x-head", HeaderValue::from_static("dummy value!"));
                    future::ok::<_, ()>(res.body("Hello world!"))
                })
                .tcp()
        })?
        .run()
        .await
}