Skip to content

Fix chunked request detection #65

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

Merged
merged 2 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion adafruit_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def _parse_headers(self):
len(title) == len("transfer-encoding")
and title.lower() == "transfer-encoding"
):
self._chunked = content.lower() == "chunked"
self._chunked = content.strip().lower() == "chunked"
self._headers[title] = content

@property
Expand Down
31 changes: 31 additions & 0 deletions tests/chunk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
path = "/testwifi/index.html"
text = b"This is a test of Adafruit WiFi!\r\nIf you can read this, its working :)"
headers = b"HTTP/1.0 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"
headers_extra_space = b"HTTP/1.0 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"


def _chunk(response, split, extra=b""):
Expand Down Expand Up @@ -111,3 +112,33 @@ def test_close_flush():

def test_close_flush_extra():
do_test_close_flush(b";blahblah; blah")


def do_test_get_text_extra_space(extra=b""):
pool = mocket.MocketPool()
pool.getaddrinfo.return_value = ((None, None, None, None, (ip, 80)),)
c = _chunk(text, 33, extra)
print(c)
sock = mocket.Mocket(headers_extra_space + c)
pool.socket.return_value = sock

s = adafruit_requests.Session(pool)
r = s.get("http://" + host + path)

sock.connect.assert_called_once_with((ip, 80))

sock.send.assert_has_calls(
[
mock.call(b"GET"),
mock.call(b" /"),
mock.call(b"testwifi/index.html"),
mock.call(b" HTTP/1.1\r\n"),
]
)
sock.send.assert_has_calls(
[
mock.call(b"Host: "),
mock.call(b"wifitest.adafruit.com"),
]
)
assert r.text == str(text, "utf-8")