Skip to content

Commit

Permalink
Fix HTTP version in debug log (#3316)
Browse files Browse the repository at this point in the history
  • Loading branch information
pquentin committed May 10, 2024
1 parent b34619f commit 5239265
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/urllib3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ def getresponse( # type: ignore[override]
headers=headers,
status=httplib_response.status,
version=httplib_response.version,
version_string=getattr(self, "_http_vsn_str", "HTTP/?"),
reason=httplib_response.reason,
preload_content=resp_options.preload_content,
decode_content=resp_options.decode_content,
Expand Down
7 changes: 2 additions & 5 deletions src/urllib3/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,17 +543,14 @@ def _make_request(
response._connection = response_conn # type: ignore[attr-defined]
response._pool = self # type: ignore[attr-defined]

# emscripten connection doesn't have _http_vsn_str
http_version = getattr(conn, "_http_vsn_str", "HTTP/?")
log.debug(
'%s://%s:%s "%s %s %s" %s %s',
'%s://%s:%s "%s %s HTTP/%s" %s %s',
self.scheme,
self.host,
self.port,
method,
url,
# HTTP version
http_version,
response.version,
response.status,
response.length_remaining,
)
Expand Down
1 change: 1 addition & 0 deletions src/urllib3/contrib/emscripten/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(
status=internal_response.status_code,
request_url=url,
version=0,
version_string="HTTP/?",
reason="",
decode_content=True,
)
Expand Down
1 change: 1 addition & 0 deletions src/urllib3/http2.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def __init__(
headers=headers,
# Following CPython, we map HTTP versions to major * 10 + minor integers
version=20,
version_string="HTTP/2",
# No reason phrase in HTTP/2
reason=None,
decode_content=decode_content,
Expand Down
4 changes: 4 additions & 0 deletions src/urllib3/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def __init__(
headers: typing.Mapping[str, str] | typing.Mapping[bytes, bytes] | None = None,
status: int,
version: int,
version_string: str,
reason: str | None,
decode_content: bool,
request_url: str | None,
Expand All @@ -329,6 +330,7 @@ def __init__(
self.headers = HTTPHeaderDict(headers) # type: ignore[arg-type]
self.status = status
self.version = version
self.version_string = version_string
self.reason = reason
self.decode_content = decode_content
self._has_decoded_content = False
Expand Down Expand Up @@ -574,6 +576,7 @@ def __init__(
headers: typing.Mapping[str, str] | typing.Mapping[bytes, bytes] | None = None,
status: int = 0,
version: int = 0,
version_string: str = "HTTP/?",
reason: str | None = None,
preload_content: bool = True,
decode_content: bool = True,
Expand All @@ -591,6 +594,7 @@ def __init__(
headers=headers,
status=status,
version=version,
version_string=version_string,
reason=reason,
decode_content=decode_content,
request_url=request_url,
Expand Down
1 change: 1 addition & 0 deletions test/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ def test_base_io(self) -> None:
resp = BaseHTTPResponse(
status=200,
version=11,
version_string="HTTP/1.1",
reason=None,
decode_content=False,
request_url=None,
Expand Down

0 comments on commit 5239265

Please sign in to comment.