@@ -1697,6 +1697,60 @@ def parse_url(url: str, sanitize: bool = True) -> "ParsedUrl":
16971697 )
16981698
16991699
1700+ def get_aws_sigv4_signed_headers (
1701+ headers : "Any" , url : "Optional[str]" = None
1702+ ) -> "Set[str]" :
1703+ # httpConnection exposes buffer, aiohttp uses header mapping.
1704+ if isinstance (headers , (str , bytes )):
1705+ authorization = headers
1706+ elif headers is None :
1707+ authorization = ""
1708+ elif hasattr (headers , "get" ):
1709+ authorization = headers .get ("Authorization" , "" )
1710+ else :
1711+ authorization = ""
1712+ for line in headers :
1713+ name , separator , value = line .partition (b":" )
1714+ if separator and name .lower () == b"authorization" :
1715+ authorization = value
1716+ break
1717+
1718+ if isinstance (authorization , bytes ):
1719+ authorization = authorization .decode ("ascii" , "ignore" )
1720+
1721+ signed_headers = set ()
1722+ if isinstance (authorization , str ):
1723+ # only AWS SigV4 authorization has the SignedHeaders parameter.
1724+ value = authorization .lstrip ()
1725+ if value .startswith (("AWS4-HMAC-SHA256" , "AWS4-ECDSA-P256-SHA256" )):
1726+ for part in value .split ("," ):
1727+ part = part .strip ()
1728+ if part .startswith ("SignedHeaders=" ):
1729+ _ , _ , header_names = part .partition ("=" )
1730+ signed_headers .update (
1731+ header .lower () for header in header_names .split (";" ) if header
1732+ )
1733+ break
1734+
1735+ if url is None :
1736+ return signed_headers
1737+
1738+ query = {
1739+ key .lower (): values for key , values in parse_qs (urlsplit (url ).query ).items ()
1740+ }
1741+ algorithm = query .get ("x-amz-algorithm" , ["" ])[0 ]
1742+ if algorithm not in ("AWS4-HMAC-SHA256" , "AWS4-ECDSA-P256-SHA256" ):
1743+ return signed_headers
1744+
1745+ # presigned requests have SignedHeaders in the URL query.
1746+ signed_headers .update (
1747+ header .lower ()
1748+ for header in query .get ("x-amz-signedheaders" , ["" ])[0 ].split (";" )
1749+ if header
1750+ )
1751+ return signed_headers
1752+
1753+
17001754def is_valid_sample_rate (rate : "Any" , source : str ) -> bool :
17011755 """
17021756 Checks the given sample rate to make sure it is valid type and value (a
0 commit comments