Issue 2550990
Created on 2018-08-11 01:56 by rouilj, last changed 2022-05-15 18:05 by rouilj.
msg6178 |
Author: [hidden] (rouilj) |
Date: 2018-08-11 01:56 |
|
The roundup-server never compresses data even if accept-encoding
includes gzip.
This code from: https://stackoverflow.com/questions/9622998/how-to-use-
content-encoding-gzip-with-python-simplehttpserver
===
Building on @velis answer above, here is how I do it. gZipping small
data is not worth the time and can increase its size. Tested with
Dalvik client.
def do_GET(self):
... get content
self.send_response(returnCode) # 200, 401, etc
...your other headers, etc...
if len(content) > 100: # don't bother
compressing small data
if 'accept-encoding' in self.headers: # case insensitive
if 'gzip' in self.headers['accept-encoding']:
content = gzipencode(content) # gzipencode defined
above in @velis answer
self.send_header('content-encoding', 'gzip')
self.send_header('content-length', len(content))
self.end_headers() # send a blank line
self.wfile.write(content)
====
could be modified to compress static assets (@@file) if the browser
will accept gzippped data. For images, javascript (e.g. bootstrap used
by jinja templates) etc this could be a real win.
Some proxy servers (e.g. hiawatha) can't compress the data being
returned by roundup-server, so the roundup server needs to do the
compression.
|
msg6180 |
Author: [hidden] (rouilj) |
Date: 2018-08-11 02:28 |
|
Adding compression function from same thread:
def gzipencode(self, content):
import StringIO
import gzip
out = StringIO.StringIO()
f = gzip.GzipFile(fileobj=out, mode='w', compresslevel=5)
f.write(content)
f.close()
return out.getvalue()
|
msg6181 |
Author: [hidden] (joseph_myers) |
Date: 2018-08-11 10:00 |
|
Would need to use io.BytesIO not StringIO for Python 3 compatibility.
|
msg7530 |
Author: [hidden] (rouilj) |
Date: 2022-05-15 18:05 |
|
This was done on issue2551147. Closing.
|
|
Date |
User |
Action |
Args |
2022-05-15 18:05:27 | rouilj | set | status: new -> closed superseder: Enable compression of http responses in roundup resolution: duplicate messages:
+ msg7530 |
2018-08-11 10:00:23 | joseph_myers | set | nosy:
+ joseph_myers messages:
+ msg6181 |
2018-08-11 02:28:12 | rouilj | set | messages:
+ msg6180 |
2018-08-11 01:56:46 | rouilj | create | |
|