Skip to content

Commit

Permalink
Revert "fix(client): send content-length even with no body"
Browse files Browse the repository at this point in the history
This reverts commit 172fdfa.
  • Loading branch information
seanmonstar committed Apr 16, 2024
1 parent d53305a commit 3705a7e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 41 deletions.
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

0 comments on commit 3705a7e

Please sign in to comment.