Skip to content

Commit

Permalink
Upgrade urllib3 and fix test
Browse files Browse the repository at this point in the history
urllib3 v2.0.0 started enforcing that the amount of data it retrieves
from the server matches the `Content-Length` header by default. See
urllib3/urllib3#2514 .

This caused some tests to fail, exposing an issue where the mock HTTP
was setting invalid Content-Length and Content-Range headers.
  • Loading branch information
pR0Ps committed Jan 19, 2024
1 parent ac5cf7e commit 1ea7011
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
],
install_requires = [
"discord.py>=2.0.0,<3.0.0",
"urllib3>=1.26.12,<2.0.0",
"urllib3>=1.26.12,<3.0.0",
"iterable-io>=1.0.0,<2.0.0",
],
packages=["slack_to_discord"],
Expand Down
5 changes: 3 additions & 2 deletions tests/test_http_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
def gen_bytes(s, e):
return b"".join(bytes([x]) for x in range(s, e))


class HTTPRangeRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
range_ = self.headers.get("Range")
Expand All @@ -37,12 +38,12 @@ def do_GET(self):
return
else:
self.send_response(HTTPStatus.PARTIAL_CONTENT)
self.send_header("Content-Range", f"bytes {start}-{end-1}/{end}")
self.send_header("Content-Range", f"bytes {start}-{end-1}/{RESP_SIZE}")
else:
self.send_response(HTTPStatus.OK)

self.send_header("Accept-Ranges", "bytes")
self.send_header("Content-Length", RESP_SIZE)
self.send_header("Content-Length", end - start)
self.end_headers()
self.wfile.write(gen_bytes(start, end))

Expand Down

0 comments on commit 1ea7011

Please sign in to comment.