WSGIPublisher improvements
Here are assorted WSGIPublisher improvements. The use-cases which triggered the issues fixed here are:
A dry-run script
# parameters: RESPONSE=None, dry=True
print 'foo'
doSomething()
if dry:
print 'DRY RUN'
RESPONSE.write(printed)
raise Exception('Dry run') # So transaction is rolled back
return printed
Without these changes, the output is the concatenation of whatever was printed here, with the standard error page. The response headers come from the error page, so the printed statements are typically rendered as HTML, which is incorrect.
A web API implementation
Such implementation must have full control over any combination of:
- transaction rollback/commit (IOW: raise an exception or not)
- response status: such code may raise an exception unknown to the publisher, which would usually end up as a 500 response. But it may have positionned a specific status, which must be preserved by the publisher.
- response headers: such code may disable the use of standard error pages in order to preserve a set of carefuly chosen headers
- response body: likewise, with the standard error disabled, such code should be able to achieve total control over the response's body
All these work fine with Medusa (non-WSGI) and were broken when switching to WSGI. These changes resolves these divergences.
Unittests are currently running on this code (as of this writing: testrunner3).
/cc @jm as I believe you oversaw the original work
/cc @georgios.dagkakis as I believe you have noticed the dry-run breakage: a solution is comming !