def test_response_with_precompressed_body_gzip(loop, test_client):
@asyncio.coroutine
def handler(request):
headers = {'Content-Encoding': 'gzip'}
zcomp = zlib.compressobj(wbits=16 + zlib.MAX_WBITS)
data = zcomp.compress(b'mydata') + zcomp.flush()
return web.Response(body=data, headers=headers)
app = web.Application()
app.router.add_get('/', handler)
client = yield from test_client(app)
resp = yield from client.get('/')
assert 200 == resp.status
data = yield from resp.read()
assert b'mydata' == data
assert resp.headers.get('Content-Encoding') == 'gzip'
评论列表
文章目录