Roundup Tracker - Issues

Issue 2550990

classification
Title: Enable compression of data by roundup-server when requested
Type: resource usage Severity: normal
Components: Web interface Versions: devel
process
Status: new Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: joseph_myers, rouilj
Priority: normal Keywords:

Created on 2018-08-11 01:56 by rouilj, last changed 2018-08-11 10:00 by joseph_myers.

Messages
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.
History
Date User Action Args
2018-08-11 10:00:23joseph_myerssetnosy: + joseph_myers
messages: + msg6181
2018-08-11 02:28:12rouiljsetmessages: + msg6180
2018-08-11 01:56:46rouiljcreate