Skip to content
Open
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
5 changes: 3 additions & 2 deletions python-ecosys/requests/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,11 @@ def request(
if not l or l == b"\r\n":
break
# print(l)
if l.startswith(b"Transfer-Encoding:"):
lowerl = l.lower()
if lowerl.startswith(b"transfer-encoding:"):
if b"chunked" in l:
chunked = True
elif l.startswith(b"Location:") and not 200 <= status <= 299:
elif lowerl.startswith(b"location:") and not 200 <= status <= 299:
if status in [301, 302, 303, 307, 308]:
redirect = str(l[10:-2], "utf-8")
if redirect.startswith("/"):
Expand Down
29 changes: 29 additions & 0 deletions python-ecosys/requests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,33 @@ def test_redirect_relative():
socket.socket = lambda *a, **k: Socket()


def test_chunked_response_lowercase_header():
socket.socket = lambda *a, **k: Socket(
read_data=b"HTTP/1.1 200 OK\r\ntransfer-encoding: chunked\r\n\r\n5\r\nhello\r\n6\r\n world\r\n0\r\n\r\n"
)
response = requests.request("GET", "http://example.com")
assert response.content == b"hello world"
socket.socket = lambda *a, **k: Socket()


def test_redirect_lowercase_location():
server = iter(
[
b"HTTP/1.1 301 OK\r\nlocation: /index\r\n\r\n",
SERVER_RESPONSE_200_OK,
]
)
socket.socket = lambda *a, **k: Socket(next(server))

response = requests.request("GET", "http://example.com")

assert response.raw._write_buffer.getvalue() == (
b"GET /index HTTP/1.1\r\nConnection: close\r\nHost: example.com\r\n\r\n"
), format_message(response)

socket.socket = lambda *a, **k: Socket()


test_simple_get()
test_get_query_anchor()
test_get_auth()
Expand All @@ -354,3 +381,5 @@ def test_redirect_relative():
test_raw_readinto_content_length()
test_redirect_absolute()
test_redirect_relative()
test_chunked_response_lowercase_header()
test_redirect_lowercase_location()
Loading