From 1dc5388a5027bb2d1a93a30e83771957d1168e76 Mon Sep 17 00:00:00 2001 From: Alex Woods Date: Thu, 20 Mar 2025 14:25:06 -0700 Subject: [PATCH] Fix encoding of path in aiohttp requests --- .../smithy-http/src/smithy_http/aio/aiohttp.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/smithy-http/src/smithy_http/aio/aiohttp.py b/packages/smithy-http/src/smithy_http/aio/aiohttp.py index febb82bff..f35ad7fbb 100644 --- a/packages/smithy-http/src/smithy_http/aio/aiohttp.py +++ b/packages/smithy-http/src/smithy_http/aio/aiohttp.py @@ -3,7 +3,9 @@ from copy import copy, deepcopy from itertools import chain from typing import TYPE_CHECKING, Any -from urllib.parse import parse_qs, urlunparse +from urllib.parse import parse_qs + +import yarl if TYPE_CHECKING: # pyright doesn't like optional imports. This is reasonable because if we use these @@ -97,10 +99,17 @@ async def send( ) as resp: return await self._marshal_response(resp) - def _serialize_uri_without_query(self, uri: URI) -> str: + def _serialize_uri_without_query(self, uri: URI) -> yarl.URL: """Serialize all parts of the URI up to and including the path.""" - components = (uri.scheme, uri.netloc, uri.path or "", "", "", "") - return urlunparse(components) + return yarl.URL.build( + scheme=uri.scheme or "", + host=uri.host, + port=uri.port, + user=uri.username, + password=uri.password, + path=uri.path or "", + encoded=True, + ) async def _marshal_response( self, aiohttp_resp: "aiohttp.ClientResponse"