def after_request_call()

in src/ab/controllers/algorithm.py [0:0]


def after_request_call(response):
    """
    todo: about the order of the handlers
    :return:
    """
    f = request.path[-4:]
    if f == ".zip":
        response.direct_passthrough = False
        gzip_buffer = BytesIO()
        with GzipFile(mode='wb',
                      compresslevel=6,
                      fileobj=gzip_buffer) as gzip_file:
            gzip_file.write(response.get_data())
        response.set_data(gzip_buffer.getvalue())

        response.headers['Content-Encoding'] = "gzip"
        response.headers['Content-Length'] = response.content_length

        etag = response.headers.get('ETag')
        if etag:
            response.headers['ETag'] = '{0}:{1}"'.format(etag[:-1], "gzip")

        vary = response.headers.get('Vary')
        if not vary:
            response.headers['Vary'] = 'Accept-Encoding'
        elif 'accept-encoding' not in vary.lower():
            response.headers['Vary'] = '{}, Accept-Encoding'.format(vary)
    else:
        pass
    return response