Skip to content

Commit abb994c

Browse files
authored
Ensure all WSGITransport environs have a SERVER_PROTOCOL (#2708)
1 parent fcf1bc7 commit abb994c

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

httpx/_transports/wsgi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def handle_request(self, request: Request) -> Response:
102102
"QUERY_STRING": request.url.query.decode("ascii"),
103103
"SERVER_NAME": request.url.host,
104104
"SERVER_PORT": str(port),
105+
"SERVER_PROTOCOL": "HTTP/1.1",
105106
"REMOTE_ADDR": self.remote_addr,
106107
}
107108
for header_key, header_value in request.headers.raw:

tests/test_wsgi.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,20 @@ def app(environ, start_response):
173173
assert response.status_code == 200
174174
assert response.text == "Hello, World!"
175175
assert server_port == expected_server_port
176+
177+
178+
def test_wsgi_server_protocol():
179+
server_protocol = None
180+
181+
def app(environ, start_response):
182+
nonlocal server_protocol
183+
server_protocol = environ["SERVER_PROTOCOL"]
184+
start_response("200 OK", [("Content-Type", "text/plain")])
185+
return [b"success"]
186+
187+
with httpx.Client(app=app, base_url="http://testserver") as client:
188+
response = client.get("/")
189+
190+
assert response.status_code == 200
191+
assert response.text == "success"
192+
assert server_protocol == "HTTP/1.1"

0 commit comments

Comments
 (0)