Skip to content

Commit 3705a7e

Browse files
committed
Revert "fix(client): send content-length even with no body"
This reverts commit 172fdfa.
1 parent d53305a commit 3705a7e

File tree

2 files changed

+6
-41
lines changed

2 files changed

+6
-41
lines changed

src/proto/h1/role.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -1288,13 +1288,6 @@ impl Client {
12881288
body
12891289
} else {
12901290
head.headers.remove(header::TRANSFER_ENCODING);
1291-
// If we know there's body coming, set a content-length.
1292-
// But only if the method normally has a body.
1293-
// GET, HEAD, and CONNECT are assumed empty.
1294-
if !is_method_assumed_empty(&head.subject.0) {
1295-
head.headers
1296-
.insert(header::CONTENT_LENGTH, HeaderValue::from_static("0"));
1297-
}
12981291
return Encoder::length(0);
12991292
};
13001293

@@ -1368,11 +1361,12 @@ impl Client {
13681361
// So instead of sending a "chunked" body with a 0-chunk,
13691362
// assume no body here. If you *must* send a body,
13701363
// set the headers explicitly.
1371-
if is_method_assumed_empty(&head.subject.0) {
1372-
Some(Encoder::length(0))
1373-
} else {
1374-
te.insert(HeaderValue::from_static("chunked"));
1375-
Some(Encoder::chunked())
1364+
match head.subject.0 {
1365+
Method::GET | Method::HEAD | Method::CONNECT => Some(Encoder::length(0)),
1366+
_ => {
1367+
te.insert(HeaderValue::from_static("chunked"));
1368+
Some(Encoder::chunked())
1369+
}
13761370
}
13771371
} else {
13781372
None
@@ -1474,11 +1468,6 @@ impl Client {
14741468
}
14751469
}
14761470

1477-
#[cfg(feature = "client")]
1478-
fn is_method_assumed_empty(method: &Method) -> bool {
1479-
matches!(method, &Method::GET | &Method::HEAD | &Method::CONNECT)
1480-
}
1481-
14821471
#[cfg(feature = "client")]
14831472
fn set_content_length(headers: &mut HeaderMap, len: u64) -> Encoder {
14841473
// At this point, there should not be a valid Content-Length

tests/client.rs

-24
Original file line numberDiff line numberDiff line change
@@ -888,30 +888,6 @@ test! {
888888
body: None,
889889
}
890890

891-
test! {
892-
name: client_post_empty_auto_length,
893-
894-
server:
895-
expected: "\
896-
POST /empty HTTP/1.1\r\n\
897-
host: {addr}\r\n\
898-
content-length: 0\r\n\
899-
\r\n\
900-
",
901-
reply: REPLY_OK,
902-
903-
client:
904-
request: {
905-
method: POST,
906-
url: "http://{addr}/empty",
907-
headers: {},
908-
},
909-
response:
910-
status: OK,
911-
headers: {},
912-
body: None,
913-
}
914-
915891
test! {
916892
name: client_head_ignores_body,
917893

0 commit comments

Comments
 (0)