Adding support for zstd in HttpCompressionMiddleware

This commit is contained in:
P. Chen 2020-10-05 21:00:58 +01:00
parent 004b40a719
commit 892dd9da57
No known key found for this signature in database
GPG Key ID: E3353B0B8B3E8B49
1 changed files with 8 additions and 0 deletions

View File

@ -14,6 +14,12 @@ try:
except ImportError:
pass
try:
import zstd
ACCEPTED_ENCODINGS.append(b'zstd')
except ImportError:
pass
class HttpCompressionMiddleware:
"""This middleware allows compressed (gzip, deflate) traffic to be
@ -67,4 +73,6 @@ class HttpCompressionMiddleware:
body = zlib.decompress(body, -15)
if encoding == b'br' and b'br' in ACCEPTED_ENCODINGS:
body = brotli.decompress(body)
if encoding == b'zstd' and b'zstd' in ACCEPTED_ENCODINGS:
body = zstd.decompress(body)
return body