Skip to content

Commit

Permalink
try fixing the HTTPConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
bentsku committed Oct 11, 2024
1 parent fa6bbac commit 2f5dcd7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/serving/test_twisted.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import io
import sys

import requests

Expand Down Expand Up @@ -42,8 +43,13 @@ def hello(request: Request):
gateway = Gateway(request_handlers=[RouterHandler(router, True)])
server = serve_twisted_gateway(gateway)
host = server.url
conn = http.client.HTTPConnection("", port=server.port)
conn.set_debuglevel(1)

if sys.platform.startswith("darwin"):
# macOS doesn't like `localhost` and has trouble resolving it
conn = http.client.HTTPConnection("", port=server.port)
else:
conn = http.client.HTTPConnection(host)

# This is what is sent:
# send: b'GET http://localhost:<port>/hello HTTP/1.1\r\nHost: localhost:<port>\r\nAccept-Encoding: identity\r\n\r\n'
# note the full URI in the HTTP request
Expand Down

0 comments on commit 2f5dcd7

Please sign in to comment.