Skip to content

Commit

Permalink
fix(h1): "Transfer-Encoding" repair code causes a panic
Browse files Browse the repository at this point in the history
  • Loading branch information
inikulin committed Jan 26, 2021
1 parent 42560c7 commit 87cb221
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ pub fn add_chunked(mut entry: OccupiedEntry<'_, HeaderValue>) {
// + 2 for ", "
let new_cap = line.as_bytes().len() + CHUNKED.len() + 2;
let mut buf = BytesMut::with_capacity(new_cap);
buf.copy_from_slice(line.as_bytes());
buf.copy_from_slice(b", ");
buf.copy_from_slice(CHUNKED.as_bytes());
buf.extend_from_slice(line.as_bytes());
buf.extend_from_slice(b", ");
buf.extend_from_slice(CHUNKED.as_bytes());

*line = HeaderValue::from_maybe_shared(buf.freeze())
.expect("original header value plus ascii is valid");
Expand Down
30 changes: 30 additions & 0 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,36 @@ test! {
body: None,
}

test! {
name: client_transfer_encoding_repair,

server:
expected: "\
GET / HTTP/1.1\r\n\
transfer-encoding: foo, chunked\r\n\
host: {addr}\r\n\
\r\n\
5\r\n\
hello\r\n\
0\r\n\r\n\
",
reply: REPLY_OK,

client:
request: {
method: GET,
url: "http://{addr}/",
headers: {
"transfer-encoding" => "foo",
},
body: "hello", // not Body::empty
},
response:
status: OK,
headers: {},
body: None,
}

test! {
name: client_get_req_body_chunked_http10,

Expand Down

0 comments on commit 87cb221

Please sign in to comment.