You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Darwin C02DN4K3MD6R 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64 x86_64 i386 MacBookPro16,1 Darwin
Description
Hyper incorrectly sets content-length: 0 on Head responses without content-length.
According to https://www.ietf.org/archive/id/draft-ietf-httpbis-semantics-19.html#name-content-length:
"A server MAY send a Content-Length header field in a response to a HEAD request (Section 9.3.2); a server MUST NOT send Content-Length in such a response unless its field value equals the decimal number of octets that would have been sent in the content of a response if the same request had used the GET method."
I tried this code:
use std::net::SocketAddr;
use hyper::{
header::HOST,
service::{make_service_fn, service_fn},
Body, Client, Request, Server, Version,
};
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
#[tokio::main]
async fn main() -> Result<(), Error> {
let on_request = service_fn(|r| {
let uri = format!("http://{}", r.headers()[HOST].to_str().unwrap());
let req = Request::builder()
.method(r.method())
.uri(uri)
.version(Version::HTTP_11)
.body(Body::empty())
.unwrap();
let client = Client::new();
client.request(req)
});
let make_svc = make_service_fn(move |_| async move { Ok::<_, Error>(on_request) });
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
let server = Server::bind(&addr).serve(make_svc);
if let Err(e) = server.await {
eprintln!("server error: {}", e);
}
Ok(())
}
jannes
changed the title
Server adds content-length: 0 to H1 Head responses without explicit content-length
Server adds content-length: 0 to Http1 Head responses
May 18, 2022
jannes
changed the title
Server adds content-length: 0 to Http1 Head responses
Server incorrectly adds content-length: 0 to Http1 Head responses
May 18, 2022
Version
0.14.18
Platform
Description
Hyper incorrectly sets
content-length: 0
on Head responses without content-length.According to https://www.ietf.org/archive/id/draft-ietf-httpbis-semantics-19.html#name-content-length:
"A server MAY send a Content-Length header field in a response to a HEAD request (Section 9.3.2); a server MUST NOT send Content-Length in such a response unless its field value equals the decimal number of octets that would have been sent in the content of a response if the same request had used the GET method."
I tried this code:
and
I expected to see this happen:
Both curl responses have no
content-length
header.Instead, this happened:
The response for the request that goes through hyper has
content-length: 0
The text was updated successfully, but these errors were encountered: