cdent / wsgi-intercept

Intercept socket connection to wsgi applications for testing
MIT License
42 stars 21 forks source link

Don't send headers until we've read some results #61

Closed cjwatson closed 4 years ago

cjwatson commented 4 years ago

If the WSGI app is a generator function (using "yield"), then it won't do anything at all until its first iteration, including setting headers or calling start_response to write the status line of the response. Turn the handle once to make sure that the app has started before writing headers.

cdent commented 4 years ago

Interesting, I'm surprised this issue hasn't shown up before. Was there a particular context in which it showed up for you?

In any case, seems like a good fix. I'll give it some real attention tomorrow.

cjwatson commented 4 years ago

Yes, it showed up in our test suite when I tried to upgrade Launchpad from wsgi-intercept 0.5.1 to 1.9.1 (we were stuck on an old version until recently, because until I did some major refactoring work we were relying on wsgi-intercept to intercept zope.testbrowser calls). The topmost item in our test middleware stack happens to be an access logger, which was most easily written as a generator.

cdent commented 4 years ago

I'll have a release of this in a few minutes.