Skip to content

Commit 5239265

Browse files
authored
Fix HTTP version in debug log (#3316)
1 parent b34619f commit 5239265

6 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/urllib3/connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ def getresponse( # type: ignore[override]
480480
headers=headers,
481481
status=httplib_response.status,
482482
version=httplib_response.version,
483+
version_string=getattr(self, "_http_vsn_str", "HTTP/?"),
483484
reason=httplib_response.reason,
484485
preload_content=resp_options.preload_content,
485486
decode_content=resp_options.decode_content,

src/urllib3/connectionpool.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,17 +543,14 @@ def _make_request(
543543
response._connection = response_conn # type: ignore[attr-defined]
544544
response._pool = self # type: ignore[attr-defined]
545545

546-
# emscripten connection doesn't have _http_vsn_str
547-
http_version = getattr(conn, "_http_vsn_str", "HTTP/?")
548546
log.debug(
549-
'%s://%s:%s "%s %s %s" %s %s',
547+
'%s://%s:%s "%s %s HTTP/%s" %s %s',
550548
self.scheme,
551549
self.host,
552550
self.port,
553551
method,
554552
url,
555-
# HTTP version
556-
http_version,
553+
response.version,
557554
response.status,
558555
response.length_remaining,
559556
)

src/urllib3/contrib/emscripten/response.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(
4545
status=internal_response.status_code,
4646
request_url=url,
4747
version=0,
48+
version_string="HTTP/?",
4849
reason="",
4950
decode_content=True,
5051
)

src/urllib3/http2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def __init__(
195195
headers=headers,
196196
# Following CPython, we map HTTP versions to major * 10 + minor integers
197197
version=20,
198+
version_string="HTTP/2",
198199
# No reason phrase in HTTP/2
199200
reason=None,
200201
decode_content=decode_content,

src/urllib3/response.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ def __init__(
318318
headers: typing.Mapping[str, str] | typing.Mapping[bytes, bytes] | None = None,
319319
status: int,
320320
version: int,
321+
version_string: str,
321322
reason: str | None,
322323
decode_content: bool,
323324
request_url: str | None,
@@ -329,6 +330,7 @@ def __init__(
329330
self.headers = HTTPHeaderDict(headers) # type: ignore[arg-type]
330331
self.status = status
331332
self.version = version
333+
self.version_string = version_string
332334
self.reason = reason
333335
self.decode_content = decode_content
334336
self._has_decoded_content = False
@@ -574,6 +576,7 @@ def __init__(
574576
headers: typing.Mapping[str, str] | typing.Mapping[bytes, bytes] | None = None,
575577
status: int = 0,
576578
version: int = 0,
579+
version_string: str = "HTTP/?",
577580
reason: str | None = None,
578581
preload_content: bool = True,
579582
decode_content: bool = True,
@@ -591,6 +594,7 @@ def __init__(
591594
headers=headers,
592595
status=status,
593596
version=version,
597+
version_string=version_string,
594598
reason=reason,
595599
decode_content=decode_content,
596600
request_url=request_url,

test/test_response.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ def test_base_io(self) -> None:
591591
resp = BaseHTTPResponse(
592592
status=200,
593593
version=11,
594+
version_string="HTTP/1.1",
594595
reason=None,
595596
decode_content=False,
596597
request_url=None,

0 commit comments

Comments
 (0)