plone / diazo

Diazo applies a static HTML theme to a dynamic website
http://diazo.org
Other
41 stars 26 forks source link

Fix broken-pipe occurences when wsgi application set a content-range header #1

Closed ericof closed 12 years ago

ericof commented 12 years ago

Diazo wsgi middleware used to update the content-length but if the application set a content-range-header the end user would get a mal-formed content and in the server we would see a broken-pipe message.

lrowe commented 12 years ago

Looking at the history and the patch, I'm a little confused as to which changes are fixing the UTF-8 problems and which are due to the Content-Range. Could you please split these up into two pull requests or merge the relevant commits together so I can review them more easily.

I think the Content-Range handling in your patch isn't right. These are generated in response to a Range request header. Instead, Diazo should remove the Range request header on requests which it expects to transform (i.e. if not self.should_ignore(request) ).

ericof commented 12 years ago

I will split the pull request for sure. (The UTF-8 will die actually)

And will implement a more robust Content-Range handling

lrowe commented 12 years ago

It should probably look something like this:

def __call__(self, environ, start_response):
    request = Request(environ)
    ignore = self.should_ignore(request)

    if not ignore:
        try:
            del request.headers['Range']
        except KeyError:
            pass

    response = request.get_response(self.app)
    app_iter = response(environ, start_response)

    if ignore or not self.should_transform(response):
        return app_iter