1111from hashlib import md5 , sha1 , sha256
1212from http .cookies import BaseCookie , SimpleCookie
1313from types import MappingProxyType , TracebackType
14- from typing import TYPE_CHECKING , Any , NamedTuple , TypedDict
14+ from typing import TYPE_CHECKING , Any , Literal , NamedTuple , TypedDict
1515
1616from multidict import CIMultiDict , CIMultiDictProxy , MultiDict , MultiDictProxy
1717from yarl import URL , Query
@@ -935,7 +935,7 @@ class ClientRequestArgs(TypedDict, total=False):
935935 cookies : BaseCookie [str ]
936936 auth : BasicAuth | None
937937 version : HttpVersion
938- compress : str | bool
938+ compress : Literal [ "deflate" , "gzip" ] | bool
939939 chunked : bool | None
940940 expect100 : bool
941941 loop : asyncio .AbstractEventLoop
@@ -979,7 +979,7 @@ def __init__(
979979 cookies : BaseCookie [str ],
980980 auth : BasicAuth | None ,
981981 version : HttpVersion ,
982- compress : str | bool ,
982+ compress : Literal [ "deflate" , "gzip" ] | bool ,
983983 chunked : bool | None ,
984984 expect100 : bool ,
985985 loop : asyncio .AbstractEventLoop ,
@@ -1099,7 +1099,9 @@ def _update_cookies(self, cookies: BaseCookie[str]) -> None:
10991099
11001100 self .headers [hdrs .COOKIE ] = c .output (header = "" , sep = ";" ).strip ()
11011101
1102- def _update_content_encoding (self , data : Any , compress : bool | str ) -> None :
1102+ def _update_content_encoding (
1103+ self , data : Any , compress : bool | Literal ["deflate" , "gzip" ]
1104+ ) -> None :
11031105 """Set request content encoding."""
11041106 self .compress = None
11051107 if not data :
@@ -1111,6 +1113,10 @@ def _update_content_encoding(self, data: Any, compress: bool | str) -> None:
11111113 "compress can not be set if Content-Encoding header is set"
11121114 )
11131115 elif compress :
1116+ if isinstance (compress , str ) and compress not in {"deflate" , "gzip" }:
1117+ raise ValueError (
1118+ "compress must be one of True, False, 'deflate', or 'gzip'"
1119+ )
11141120 self .compress = compress if isinstance (compress , str ) else "deflate"
11151121 self .headers [hdrs .CONTENT_ENCODING ] = self .compress
11161122 self .chunked = True # enable chunked, no need to deal with length
0 commit comments