diff --git a/packages/smithy-http/.changes/next-release/smithy-http-bugfix-20251017171341.json b/packages/smithy-http/.changes/next-release/smithy-http-bugfix-20251017171341.json new file mode 100644 index 00000000..d8880d55 --- /dev/null +++ b/packages/smithy-http/.changes/next-release/smithy-http-bugfix-20251017171341.json @@ -0,0 +1,4 @@ +{ + "type": "bugfix", + "description": "add port to CRT HTTP client's host header" +} \ No newline at end of file diff --git a/packages/smithy-http/src/smithy_http/aio/crt.py b/packages/smithy-http/src/smithy_http/aio/crt.py index 4dd3232b..a450ef9c 100644 --- a/packages/smithy-http/src/smithy_http/aio/crt.py +++ b/packages/smithy-http/src/smithy_http/aio/crt.py @@ -273,7 +273,7 @@ def _marshal_request( headers_list: list[tuple[str, str]] = [] if "host" not in request.fields: request.fields.set_field( - Field(name="host", values=[request.destination.host]) + Field(name="host", values=[request.destination.netloc]) ) if "accept" not in request.fields: diff --git a/packages/smithy-http/tests/unit/aio/test_crt.py b/packages/smithy-http/tests/unit/aio/test_crt.py index 5b9e851e..886bb5f2 100644 --- a/packages/smithy-http/tests/unit/aio/test_crt.py +++ b/packages/smithy-http/tests/unit/aio/test_crt.py @@ -45,6 +45,27 @@ def test_client_marshal_request() -> None: assert crt_request.path == "/path?key1=value1&key2=value2" +@pytest.mark.parametrize( + "host,expected", + [ + ("example.com", "example.com:8443"), + ("2001:db8::1", "[2001:db8::1]:8443"), + ], +) +async def test_port_included_in_host_header(host: str, expected: str) -> None: + client = AWSCRTHTTPClient() + request = HTTPRequest( + method="GET", + destination=URI( + host=host, path="/path", query="key1=value1&key2=value2", port=8443 + ), + body=BytesIO(), + fields=Fields(), + ) + crt_request = client._marshal_request(request) # type: ignore + assert crt_request.headers.get("host") == expected # type: ignore + + async def test_body_generator_bytes() -> None: """Test body generator with bytes input.""" client = AWSCRTHTTPClient()