Skip to content

Commit d468727

Browse files
committed
add test for response with newlines instead of \r\n
While the HTTP standard specifies that the status-line and header-fields should be terminated with a CRLF (\r\n), many implementations on the internet would wrongly output only LF (\n). This is even recognized in the RFC which suggests that a LF may be recognized as a line terminator. https://tools.ietf.org/html/rfc7230#section-3.5 > Although the line terminator for the start-line and header fields is > the sequence CRLF, a recipient MAY recognize a single LF as a line > terminator and ignore any preceding CR. This commit introduces a test for a response with only LF newlines.
1 parent 7a2a71a commit d468727

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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)