Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ params. However aiohttp does provide a nice
print("Passed in GET", get_params)


Sending pre-compressed data
---------------------------

To include data in the response that is already compressed, do not call
`enable_compression`. Instead, set the `Content-Encoding` header explicitly:

@asyncio.coroutine
def handler(request):
headers = {'Content-Encoding': 'gzip'}
deflated_data = zlib.compress(b'mydata')
return web.Response(body=deflated_data, headers=headers)


Handling POST data
------------------

Expand Down
20 changes: 20 additions & 0 deletions tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os.path
import socket
import unittest
import zlib
from multidict import MultiDict
from aiohttp import log, web, request, FormData, ClientSession, TCPConnector
from aiohttp.protocol import HttpVersion, HttpVersion10, HttpVersion11
Expand Down Expand Up @@ -792,6 +793,25 @@ def go():

self.loop.run_until_complete(go())

def test_response_with_precompressed_body(self):
@asyncio.coroutine
def handler(request):
headers = {'Content-Encoding': 'gzip'}
deflated_data = zlib.compress(b'mydata')
return web.Response(body=deflated_data, headers=headers)

@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
client = ClientSession(loop=self.loop)
resp = yield from client.get(url)
self.assertEqual(200, resp.status)
data = yield from resp.read()
self.assertEqual(b'mydata', data)
self.assertEqual(resp.headers.get('CONTENT-ENCODING'), 'deflate')
yield from resp.release()
client.close()

def test_stream_response_multiple_chunks(self):
@asyncio.coroutine
def handler(request):
Expand Down