Issue #1097 new

Patch to support trailer headers for streamed responses

Anonymous created an issue

I am attaching a patch to CP 3.1.2 which adds support for trailer headers for streamed (chunked) responses. If streaming, response headers are reset when body generation begins. Any response.headers set after that will be output at the end as trailer headers. The application is expected to set Trailer header appropriately if they will use this; CP will not generate that header as it can't know if trailer headers will be present or not, and in any case, Trailer is SHOULD not MUST feature.

Because WSGI doesn't appear to have this concept, and I didn't want to change existing API definitions, I used custom cherrypy.trailer_headers element in environ object for this. It seems there's precedent for this type of extension, but I can change this if you feel some other solution would be better.

I also modified test_conn.py to include tests on this. Please note that it's impossible to actually test the trailer headers arrive in the test framework because httplib.HTTPResponse discards trailer headers. I used curl and strace to verify the trailer is transmitted and processed correctly. All existing tests pass without additional failures.

Reported by lat@cern.ch

Comments (0)

  1. Log in to comment