From a3d21f20b281ba98f75ae6442b59a9e5723e66fc Mon Sep 17 00:00:00 2001 From: RamanjaneyuluIdavalapati Date: Fri, 6 Jul 2018 16:34:49 +0200 Subject: [PATCH] gzip compression is supported --- .travis.yml | 4 ++-- kwikapi/tornado/kwikapi_tornado.py | 13 ++++++++++++- setup.py | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3710bcc..16dfd4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,8 @@ deploy: skip_cleanup: true api_key: secure: 3wIm6vrNmdIP50NIUtig33S34FonRqxGnRRY55oiMN4BD5xeo2iQb8TmWMswwqVTuO09C3Cd7kBxP5JxBR+dCuVZZRqpL/8E6JUTaGyZcQ/9HgB8FwYXRCj2ASPDHfmjmZ8F3GIX19akJLKiTThB1WU3XidcZ9tZgwvOmf10Jy7IXiddRKwucVVVy608H9hUXPpIVMzqcFfeU2KeXcotU0J2eZyqso/RCPNw4qDZKFvkiKT2MM4B6FgY7WYorNUW1JXdh8dcAV7vb0oNB0iUNLMCpNHFqoyfOHcxKUgP81wMS8TY5wWLuQxUESg1eyo7Q9gwegOseySU1NBjlPyltVVWtulltM2sge0KgVoLgQRia/LeKnCynSi2r8aic1VoMUDEH5ZfWuJJrFHOJyKCNapp3MKK42UXDo28NpdjjUUgJOOukWpXsaVmPhPXpWWQlZM9YMeMPxTUpm3ZACs2WmHssVwO7EaTaJ45ctAf4m0csb7Ri5IyR5iLy9YEX6fuNMoNVCI6lE7ax38pf1mkgamZTJtvEFr+ekKMXq3heVk598rA2P7hzI5Z6Zx7S8GyQz4vveSTk/pY3StX1ScU3ULnLQaEjP1LVI3pu6R5w7PdQ+Ew6fPmU7RpD8rZPKfFoBcby1mf2Mb/HNk8jXPTHTmyTKBB+othHHg4BWM3Kuw= - name: kwikapi.tornado-0.2.6 - tag_name: 0.2.6 + name: kwikapi.tornado-0.2.7 + tag_name: 0.2.7 on: repo: deep-compute/kwikapi.tornado - provider: pypi diff --git a/kwikapi/tornado/kwikapi_tornado.py b/kwikapi/tornado/kwikapi_tornado.py index 8dac4c8..3b9f62c 100644 --- a/kwikapi/tornado/kwikapi_tornado.py +++ b/kwikapi/tornado/kwikapi_tornado.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -* import asyncio +import zlib from tornado.web import RequestHandler as TornadoRequestHandler from tornado.web import asynchronous @@ -45,7 +46,17 @@ def write(self, data, proto, stream=False): n, t = super().write(data, proto, stream=stream) if not stream: - self.headers['Content-Length'] = n.value + nbytes = n.value + + accept_enc = self._req_hdlr.request.headers['Accept-Encoding'] + accept_enc = set([e.strip().lower() for e in accept_enc.split(',') if e.strip()]) + + if 'gzip' in accept_enc: + self._data = zlib.compress(self._data) + nbytes = len(self._data) + self.headers['Content-Encoding'] = 'gzip' + + self.headers['Content-Length'] = nbytes self._stream = stream diff --git a/setup.py b/setup.py index 4178977..b54b507 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages # https://docs.djangoproject.com/en/1.11/intro/reusable-apps/ -version = '0.2.6' +version = '0.2.7' setup( name="kwikapi-tornado", version=version,