Skip to content

Commit eb4ebf2

Browse files
authored
Merge pull request #85 from gdamjan/master
add test for response with newlines instead of \r\n
2 parents 7a2a71a + 25638dd commit eb4ebf2

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/client/decode.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ where
4444
if idx >= 3 && &buf[idx - 3..=idx] == [CR, LF, CR, LF] {
4545
break;
4646
}
47+
if idx >= 1 && &buf[idx - 1..=idx] == [LF, LF] {
48+
break;
49+
}
4750
}
4851

4952
// Convert our header buf into an httparse instance, and validate.

tests/client.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,23 @@ async fn test_multiple_header_values_for_same_header_name() {
4747

4848
pretty_assertions::assert_eq!(res.header(&headers::SET_COOKIE).unwrap().len(), 2);
4949
}
50+
51+
#[async_std::test]
52+
async fn test_response_newlines() {
53+
let response_fixture = File::open(fixture_path("fixtures/response-newlines.txt"))
54+
.await
55+
.unwrap();
56+
57+
let res = client::decode(response_fixture).await.unwrap();
58+
59+
pretty_assertions::assert_eq!(
60+
res.header(&headers::CONTENT_LENGTH)
61+
.unwrap()
62+
.last()
63+
.unwrap()
64+
.as_str()
65+
.parse::<usize>()
66+
.unwrap(),
67+
78
68+
);
69+
}

tests/fixtures/response-newlines.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HTTP/1.1 200 OK
2+
content-length: 78
3+
date: {DATE}
4+
content-type: text/plain; charset=utf-8
5+
6+
http specifies headers are separated with \r\n but many servers don't do that

0 commit comments

Comments
 (0)