Skip to content

Commit

Permalink
Ensure all WSGITransport environs have a SERVER_PROTOCOL (#2708)
Browse files Browse the repository at this point in the history
  • Loading branch information
lazorchakp committed May 19, 2023
1 parent fcf1bc7 commit abb994c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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"

0 comments on commit abb994c

Please sign in to comment.