|
26 | 26 |
|
27 | 27 | from . import hdrs
|
28 | 28 | from .base_protocol import BaseProtocol
|
29 |
| -from .compression_utils import HAS_BROTLI, BrotliDecompressor, ZLibDecompressor |
| 29 | +from .compression_utils import ( |
| 30 | + HAS_BROTLI, |
| 31 | + HAS_ZSTD, |
| 32 | + BrotliDecompressor, |
| 33 | + ZLibDecompressor, |
| 34 | + ZSTDDecompressor, |
| 35 | +) |
30 | 36 | from .helpers import (
|
31 | 37 | _EXC_SENTINEL,
|
32 | 38 | DEBUG,
|
@@ -527,7 +533,7 @@ def parse_headers(
|
527 | 533 | enc = headers.get(hdrs.CONTENT_ENCODING)
|
528 | 534 | if enc:
|
529 | 535 | enc = enc.lower()
|
530 |
| - if enc in ("gzip", "deflate", "br"): |
| 536 | + if enc in ("gzip", "deflate", "br", "zstd"): |
531 | 537 | encoding = enc
|
532 | 538 |
|
533 | 539 | # chunking
|
@@ -930,14 +936,21 @@ def __init__(self, out: StreamReader, encoding: Optional[str]) -> None:
|
930 | 936 | self.encoding = encoding
|
931 | 937 | self._started_decoding = False
|
932 | 938 |
|
933 |
| - self.decompressor: Union[BrotliDecompressor, ZLibDecompressor] |
| 939 | + self.decompressor: Union[BrotliDecompressor, ZLibDecompressor, ZSTDDecompressor] |
934 | 940 | if encoding == "br":
|
935 | 941 | if not HAS_BROTLI:
|
936 | 942 | raise ContentEncodingError(
|
937 | 943 | "Can not decode content-encoding: brotli (br). "
|
938 | 944 | "Please install `Brotli`"
|
939 | 945 | )
|
940 | 946 | self.decompressor = BrotliDecompressor()
|
| 947 | + elif encoding == "zstd": |
| 948 | + if not HAS_ZSTD: |
| 949 | + raise ContentEncodingError( |
| 950 | + "Can not decode content-encoding: zstandard (zstd). " |
| 951 | + "Please install `zstandard`" |
| 952 | + ) |
| 953 | + self.decompressor = ZSTDDecompressor() |
941 | 954 | else:
|
942 | 955 | self.decompressor = ZLibDecompressor(encoding=encoding)
|
943 | 956 |
|
|
0 commit comments