Skip to content

Commit 28a32c6

Browse files
SamRemisalexgromero
authored andcommitted
Fix host header port mismatch in signing (smithy-lang#578)
1 parent 6e9acda commit 28a32c6

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "bugfix",
3+
"description": "add port to CRT HTTP client's host header"
4+
}

packages/smithy-http/src/smithy_http/aio/crt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def _marshal_request(
273273
headers_list: list[tuple[str, str]] = []
274274
if "host" not in request.fields:
275275
request.fields.set_field(
276-
Field(name="host", values=[request.destination.host])
276+
Field(name="host", values=[request.destination.netloc])
277277
)
278278

279279
if "accept" not in request.fields:

packages/smithy-http/tests/unit/aio/test_crt.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ def test_client_marshal_request() -> None:
4545
assert crt_request.path == "/path?key1=value1&key2=value2"
4646

4747

48+
@pytest.mark.parametrize(
49+
"host,expected",
50+
[
51+
("example.com", "example.com:8443"),
52+
("2001:db8::1", "[2001:db8::1]:8443"),
53+
],
54+
)
55+
async def test_port_included_in_host_header(host: str, expected: str) -> None:
56+
client = AWSCRTHTTPClient()
57+
request = HTTPRequest(
58+
method="GET",
59+
destination=URI(
60+
host=host, path="/path", query="key1=value1&key2=value2", port=8443
61+
),
62+
body=BytesIO(),
63+
fields=Fields(),
64+
)
65+
crt_request = client._marshal_request(request) # type: ignore
66+
assert crt_request.headers.get("host") == expected # type: ignore
67+
68+
4869
async def test_body_generator_bytes() -> None:
4970
"""Test body generator with bytes input."""
5071
client = AWSCRTHTTPClient()

0 commit comments

Comments
 (0)