Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 94
Added ability to use LF, not only CRLF delimiter for response Headers and Body#115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
fda65a2d3b2ef2b2f70e9ce26dc7af7b481341f63274693fc489de4def27d89a94d7288aa9e7f1aefea0f688615ca534f7a1197d6File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| import re | ||
| import pytest | ||
| from .._receivebuffer import ReceiveBuffer | ||
| @@ -12,15 +16,13 @@ def test_receivebuffer(): | ||
| assert len(b) == 3 | ||
| assert bytes(b) == b"123" | ||
| b.compress() | ||
| assert bytes(b) == b"123" | ||
| assert b.maybe_extract_at_most(2) == b"12" | ||
| assert b | ||
| assert len(b) == 1 | ||
| assert bytes(b) == b"3" | ||
| b.compress() | ||
| assert bytes(b) == b"3" | ||
| assert b.maybe_extract_at_most(10) == b"3" | ||
| @@ -33,32 +35,35 @@ def test_receivebuffer(): | ||
| # maybe_extract_until_next | ||
| ################################################################ | ||
| b += b"12345a6789aa" | ||
| b += b"123\n456\r\n789\r\n" | ||
| assert b.maybe_extract_until_next(b"a") == b"12345a" | ||
| assert bytes(b) == b"6789aa" | ||
| assert b.maybe_extract_next_line() == b"123\n456\r\n" | ||
| assert bytes(b) == b"789\r\n" | ||
| assert b.maybe_extract_until_next(b"aaa") is None | ||
| assert bytes(b) == b"6789aa" | ||
| assert b.maybe_extract_next_line() == b"789\r\n" | ||
| assert bytes(b) == b"" | ||
| b += b"a12" | ||
| assert b.maybe_extract_until_next(b"aaa") == b"6789aaa" | ||
| assert bytes(b) == b"12" | ||
| b += b"12\r" | ||
| assert b.maybe_extract_next_line() is None | ||
| assert bytes(b) == b"12\r" | ||
| # check repeated searches for the same needle, triggering the | ||
| # pickup-where-we-left-off logic | ||
| b += b"345" | ||
| assert b.maybe_extract_until_next(b"aaa") is None | ||
| b += b"345\n\r" | ||
| assert b.maybe_extract_next_line() is None | ||
| assert bytes(b) == b"12\r345\n\r" | ||
| b += b"6789aaa123" | ||
| assert b.maybe_extract_until_next(b"aaa") == b"123456789aaa" | ||
| assert bytes(b) == b"123" | ||
| # here we stopped at the middle of b"\r\n" delimiter | ||
| b += b"\n6789aaa123\r\n" | ||
| assert b.maybe_extract_next_line() == b"12\r345\n\r\n" | ||
| assert b.maybe_extract_next_line() == b"6789aaa123\r\n" | ||
| assert b.maybe_extract_next_line() is None | ||
| assert bytes(b) == b"" | ||
| ################################################################ | ||
| # maybe_extract_lines | ||
| ################################################################ | ||
| b += b"\r\na: b\r\nfoo:bar\r\n\r\ntrailing" | ||
| b += b"123\r\na: b\r\nfoo:bar\r\n\r\ntrailing" | ||
| lines = b.maybe_extract_lines() | ||
| assert lines == [b"123", b"a: b", b"foo:bar"] | ||
| assert bytes(b) == b"trailing" | ||
| @@ -76,3 +81,54 @@ def test_receivebuffer(): | ||
| b += b"\r\ntrailing" | ||
| assert b.maybe_extract_lines() == [] | ||
| assert bytes(b) == b"trailing" | ||
| @pytest.mark.parametrize( | ||
| "data", | ||
| [ | ||
| pytest.param( | ||
| ( | ||
| b"HTTP/1.1 200 OK\r\n", | ||
| b"Content-type: text/plain\r\n", | ||
| b"Connection: close\r\n", | ||
| b"\r\n", | ||
| b"Some body", | ||
| ), | ||
| id="with_crlf_delimiter", | ||
| ), | ||
| pytest.param( | ||
| ( | ||
| b"HTTP/1.1 200 OK\n", | ||
| b"Content-type: text/plain\n", | ||
| b"Connection: close\n", | ||
| b"\n", | ||
| b"Some body", | ||
| ), | ||
| id="with_lf_only_delimiter", | ||
| ), | ||
| pytest.param( | ||
| ( | ||
| b"HTTP/1.1 200 OK\n", | ||
| b"Content-type: text/plain\r\n", | ||
| b"Connection: close\n", | ||
| b"\n", | ||
| b"Some body", | ||
| ), | ||
| id="with_mixed_crlf_and_lf", | ||
| ), | ||
| ], | ||
| ) | ||
| def test_receivebuffer_for_invalid_delimiter(data): | ||
| b = ReceiveBuffer() | ||
| for line in data: | ||
| b += line | ||
| lines = b.maybe_extract_lines() | ||
| assert lines == [ | ||
| b"HTTP/1.1 200 OK", | ||
| b"Content-type: text/plain", | ||
| b"Connection: close", | ||
| ] | ||
| assert bytes(b) == b"Some body" | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add a few similar tests to ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added similar tests to | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Added support for servers with broken line endings. | ||
| After this change h11 accepts both ``\r\n`` and ``\n`` as a headers delimiter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
maybe_extract_next_line, we store the raw buffer length inself._next_line_searchand then do the subtraction when we use it. Inmaybe_extract_lines, we store the "pre-subtracted" value, so we can use it directly. This inconsistency is kind of confusing :-). We should switch one of them so they match.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As soon as I rewrote both methods using
_extract(...)method, this issue resolved (both methods works with offsets)