Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 36bf309

Browse files
committed
Add support for brotli compression
1 parent 0ac3471 commit 36bf309

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

hyper/http20/response.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99
import logging
1010
import zlib
11+
import brotli
1112

1213
from ..common.decoder import DeflateDecoder
1314
from ..common.headers import HTTPHeaderMap
@@ -31,6 +32,7 @@ def strip_headers(headers):
3132

3233
decompressors = {
3334
b'gzip': lambda: zlib.decompressobj(16 + zlib.MAX_WBITS),
35+
b'br': brotli.Decompressor,
3436
b'deflate': DeflateDecoder
3537
}
3638

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def run_tests(self):
7777
'Programming Language :: Python :: Implementation :: CPython',
7878
],
7979
install_requires=[
80-
'h2>=2.4,<3.0,!=2.5.0', 'hyperframe>=3.2,<4.0', 'rfc3986>=1.1.0,<2.0'
80+
'h2>=2.4,<3.0,!=2.5.0', 'hyperframe>=3.2,<4.0', 'rfc3986>=1.1.0,<2.0', 'brotlipy>=0.7.0,<1.0'
8181
],
8282
tests_require=['pytest', 'requests', 'mock'],
8383
cmdclass={'test': PyTest},

test/test_hyper.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import pytest
2727
import socket
2828
import zlib
29+
import brotli
2930
from io import BytesIO
3031

3132
TEST_DIR = os.path.abspath(os.path.dirname(__file__))
@@ -1088,6 +1089,15 @@ def test_response_transparently_decrypts_gzip(self):
10881089

10891090
assert resp.read() == b'this is test data'
10901091

1092+
def test_response_transparently_decrypts_brotli(self):
1093+
headers = HTTPHeaderMap(
1094+
[(':status', '200'), ('content-encoding', 'br')]
1095+
)
1096+
body = brotli.compress(b'this is test data')
1097+
resp = HTTP20Response(headers, DummyStream(body))
1098+
1099+
assert resp.read() == b'this is test data'
1100+
10911101
def test_response_transparently_decrypts_real_deflate(self):
10921102
headers = HTTPHeaderMap(
10931103
[(':status', '200'), ('content-encoding', 'deflate')]

0 commit comments

Comments
 (0)