@@ -212,9 +212,6 @@ def _apply_required_fields(
212212 request .fields .set_field (
213213 Field (name = "X-Amz-Security-Token" , values = [identity .session_token ])
214214 )
215- if "host" not in request .fields :
216- host = self ._normalize_host_field (uri = request .destination ) # type: ignore - TODO(pyright)
217- request .fields .set_field (Field (name = "host" , values = [host ]))
218215
219216 def canonical_request (
220217 self , * , signing_properties : SigV4SigningProperties , request : AWSRequest
@@ -332,6 +329,11 @@ def _normalize_signing_fields(self, *, request: AWSRequest) -> dict[str, str]:
332329 for field in request .fields
333330 if self ._is_signable_header (field .name .lower ())
334331 }
332+ if "host" not in normalized_fields :
333+ normalized_fields ["host" ] = self ._normalize_host_field (
334+ uri = request .destination # type: ignore - TODO(pyright)
335+ )
336+
335337 return dict (sorted (normalized_fields .items ()))
336338
337339 def _is_signable_header (self , field_name : str ):
@@ -344,10 +346,7 @@ def _normalize_host_field(self, *, uri: URI) -> str:
344346 uri_dict = uri .to_dict ()
345347 uri_dict .update ({"port" : None })
346348 uri = URI (** uri_dict )
347- host_header = uri .host
348- if port := uri .port :
349- host_header += f":{ port } "
350- return host_header
349+ return uri .netloc
351350
352351 def _format_canonical_fields (self , * , fields : dict [str , str ]) -> str :
353352 return "" .join (
@@ -590,9 +589,6 @@ async def _apply_required_fields(
590589 request .fields .set_field (
591590 Field (name = "X-Amz-Security-Token" , values = [identity .session_token ])
592591 )
593- if "host" not in request .fields :
594- host = await self ._normalize_host_field (uri = request .destination ) # type: ignore - TODO(pyright)
595- request .fields .set_field (Field (name = "host" , values = [host ]))
596592
597593 async def canonical_request (
598594 self , * , signing_properties : SigV4SigningProperties , request : AWSRequest
@@ -713,6 +709,10 @@ async def _normalize_signing_fields(self, *, request: AWSRequest) -> dict[str, s
713709 for field in request .fields
714710 if self ._is_signable_header (field .name .lower ())
715711 }
712+ if "host" not in normalized_fields :
713+ normalized_fields ["host" ] = await self ._normalize_host_field (
714+ uri = request .destination # type: ignore - TODO(pyright)
715+ )
716716
717717 return dict (sorted (normalized_fields .items ()))
718718
@@ -726,10 +726,7 @@ async def _normalize_host_field(self, *, uri: URI) -> str:
726726 uri_dict = uri .to_dict ()
727727 uri_dict .update ({"port" : None })
728728 uri = URI (** uri_dict )
729- host_header = uri .host
730- if port := uri .port :
731- host_header += f":{ port } "
732- return host_header
729+ return uri .netloc
733730
734731 async def _format_canonical_fields (self , * , fields : dict [str , str ]) -> str :
735732 return "" .join (
0 commit comments