app_iter close method is not called when you have two WebOb middlewares on HEAD requests #74

thefunny42 opened this Issue Sep 10, 2012 · 2 comments


None yet

4 participants



There is an issue with the class EmptyResponse of (line 1221).
The first if in the constructor is formulated like this:

        if app_iter and hasattr(app_iter, 'close'):

And should be more likely something like:

        if app_iter is not None and hasattr(app_iter, 'close'):

The bug I encounter is that my main application uses the close method, and I have at least two middlewares using WebOb in my WSGI stack. Now when a HEAD request occurs, WebOb returns this EmptyResponse iterator instead of the one of the application, still mapping the close method of the original iterator to this new one. However it defines as well the __len__ method to return zero. Now if you have two middlewares using WebOb, the first middleware will replace the application iterator with this EmptyResponse, and the second will do the same thing, however the if used to map the close method will fail (because of the __len__ method), and the close method of the application will never be mapped, and called.

This bug is really a blocking point for me, and I would greatly appreciate to have it fixed quickly.

Thank you,

maluke commented Sep 10, 2012

I understand the issue, but please provide a test case to reproduce this.


This has been fixed by bertjwregeer@951a41c

And it only took us a couple of years, and a lot of hair pulling debugging on #pyramid on IRC.

@mmerickel mmerickel closed this Nov 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment