Roundup Tracker - Issues

Issue 2550990

Title: Enable compression of data by roundup-server when requested
Type: resource usage Severity: normal
Components: Web interface Versions: devel
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.

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:

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


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 
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)
    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.
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