I noticed that the gzip middleware is not including a 'Vary:
Accept-Encoding' when gzipping it's replies. This causes problems when the
server is behind a cache, because the cache will happily serve up a cached
gzipped version of a resource to a client that doesn't support gzip.

Here's the middleware that fixes it, and a patch to paste/trunk attached.

def fix_gzip_encoding(app):
    """
    Paste's GzipMiddleware fails to include Vary: Accept-Encoding in the
headers.

    The problem is when you're behind a cache. If one client requests
    a resource with Accept-Encoding: gzip, and then another client
    requests the same resource who doesn't understand gzip, then the
    second client gets a gzipped reply.
    """
    def fix_vary_app(environ, start_response):

        def vary_start_response(status, headers):
            gzipped = False
            have_vary = False
            for header, value in headers:
                header = header.lower()
                if header == 'content-encoding' and 'gzip' in value:
                    gzipped = True
                elif header == 'vary' and 'encoding' in value:
                    have_vary = True

                if gzipped and have_vary:
                    headers.append(('Vary', 'Accept-Encoding'))
                    break

            return start_response(status, headers)


        return app(environ, vary_start_response)

    return fix_vary_app

Attachment: paste-gzip-vary.patch
Description: Binary data

_______________________________________________
Paste-users mailing list
[email protected]
http://webwareforpython.org/cgi-bin/mailman/listinfo/paste-users

Reply via email to