Skip to content
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
Ensure all WSGITransport environs have a SERVER_PROTOCOL
  • Loading branch information
lazorchakp committed May 18, 2023
commit 81eabe0fbfb12a9447d97cea563585f352c34f2e
1 change: 1 addition & 0 deletions httpx/_transports/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def handle_request(self, request: Request) -> Response:
"QUERY_STRING": request.url.query.decode("ascii"),
"SERVER_NAME": request.url.host,
"SERVER_PORT": str(port),
"SERVER_PROTOCOL": "HTTP/1.1",
"REMOTE_ADDR": self.remote_addr,
}
for header_key, header_value in request.headers.raw:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,20 @@ def app(environ, start_response):
assert response.status_code == 200
assert response.text == "Hello, World!"
assert server_port == expected_server_port


def test_wsgi_server_protocol():
server_protocol = None

def app(environ, start_response):
nonlocal server_protocol
server_protocol = environ["SERVER_PROTOCOL"]
start_response("200 OK", [("Content-Type", "text/plain")])
return [b"success"]

with httpx.Client(app=app, base_url="http://testserver") as client:
response = client.get("/")

assert response.status_code == 200
assert response.text == "success"
assert server_protocol == "HTTP/1.1"