Skip to content

Commit

Permalink
feat: Warn about br handling if brotlipy is not installed scrapy#4697
Browse files Browse the repository at this point in the history
  • Loading branch information
Dushatar committed Mar 5, 2021
1 parent f95ebd8 commit 5187f7a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scrapy/downloadermiddlewares/httpcompression.py
@@ -1,5 +1,7 @@
import io
import zlib
import logging
logger = logging.getLogger(__name__)

from scrapy.utils.gz import gunzip
from scrapy.http import Response, TextResponse
Expand All @@ -13,6 +15,8 @@
import brotli
ACCEPTED_ENCODINGS.append(b'br')
except ImportError:
msg = ("brotli is not installed")
logger.warning(msg)
pass

try:
Expand Down Expand Up @@ -72,8 +76,11 @@ def _decode(self, body, encoding):
# http://www.port80software.com/200ok/archive/2005/10/31/868.aspx
# http://www.gzip.org/zlib/zlib_faq.html#faq38
body = zlib.decompress(body, -15)
if encoding == b'br' and b'br' in ACCEPTED_ENCODINGS:
body = brotli.decompress(body)
if encoding == b'br':
if b'br' in ACCEPTED_ENCODINGS:
body = brotli.decompress(body)
else:
raise ImportError('brotlipy is not installed')
if encoding == b'zstd' and b'zstd' in ACCEPTED_ENCODINGS:
# Using its streaming API since its simple API could handle only cases
# where there is content size data embedded in the frame
Expand Down

0 comments on commit 5187f7a

Please sign in to comment.