Skip to content

Commit 7c8ee70

Browse files
committed
Update CRT HTTP client to include the port in the host for the CRT client if it adds the header
1 parent 42d669f commit 7c8ee70

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ def test_client_marshal_request() -> None:
4444
assert crt_request.method == "GET"
4545
assert crt_request.path == "/path?key1=value1&key2=value2"
4646

47+
async def test_port_included_in_host_header() -> None:
48+
client = AWSCRTHTTPClient()
49+
request = HTTPRequest(
50+
method="GET",
51+
destination=URI(
52+
host="example.com", path="/path", query="key1=value1&key2=value2", port=8443
53+
),
54+
body=BytesIO(),
55+
fields=Fields(),
56+
)
57+
crt_request, _ = await client._marshal_request(request) # type: ignore
58+
assert crt_request.headers.get("host") == "example.com:8443" # type: ignore
59+
4760

4861
async def test_body_generator_bytes() -> None:
4962
"""Test body generator with bytes input."""

0 commit comments

Comments
 (0)