Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix(client): send content-length even with no body" #3633

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions src/proto/h1/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,13 +1288,6 @@ impl Client {
body
} else {
head.headers.remove(header::TRANSFER_ENCODING);
// If we know there's body coming, set a content-length.
// But only if the method normally has a body.
// GET, HEAD, and CONNECT are assumed empty.
if !is_method_assumed_empty(&head.subject.0) {
head.headers
.insert(header::CONTENT_LENGTH, HeaderValue::from_static("0"));
}
return Encoder::length(0);
};

Expand Down Expand Up @@ -1368,11 +1361,12 @@ impl Client {
// So instead of sending a "chunked" body with a 0-chunk,
// assume no body here. If you *must* send a body,
// set the headers explicitly.
if is_method_assumed_empty(&head.subject.0) {
Some(Encoder::length(0))
} else {
te.insert(HeaderValue::from_static("chunked"));
Some(Encoder::chunked())
match head.subject.0 {
Method::GET | Method::HEAD | Method::CONNECT => Some(Encoder::length(0)),
_ => {
te.insert(HeaderValue::from_static("chunked"));
Some(Encoder::chunked())
}
}
} else {
None
Expand Down Expand Up @@ -1474,11 +1468,6 @@ impl Client {
}
}

#[cfg(feature = "client")]
fn is_method_assumed_empty(method: &Method) -> bool {
matches!(method, &Method::GET | &Method::HEAD | &Method::CONNECT)
}

#[cfg(feature = "client")]
fn set_content_length(headers: &mut HeaderMap, len: u64) -> Encoder {
// At this point, there should not be a valid Content-Length
Expand Down
24 changes: 0 additions & 24 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,30 +888,6 @@ test! {
body: None,
}

test! {
name: client_post_empty_auto_length,

server:
expected: "\
POST /empty HTTP/1.1\r\n\
host: {addr}\r\n\
content-length: 0\r\n\
\r\n\
",
reply: REPLY_OK,

client:
request: {
method: POST,
url: "http://{addr}/empty",
headers: {},
},
response:
status: OK,
headers: {},
body: None,
}

test! {
name: client_head_ignores_body,

Expand Down
Loading