Open JanKlopper opened 7 years ago
It's not so much that the headers on the response are reset, it's that the newly created response has no headers.
Creating a new Response
object suggests the existing one should not be used, for whatever reason. If the cookies, header, content-type, or anything should be used from the existing half-created response, it's up to the developer to assign those. Having them somehow appear would definitely be a very surprising thing, and is not behavior I've seen in any other web frameworks.
In the example you've given, assuming cookies or other headers have been set previously, the solution seems to be setting the content type and returning the content:
self.req.response.content_type = 'application/javascript'
return self.parser.Parse('mycode.js')
When setting a cookie, and the returning a response object the response object ignores any previous set cookies or headers.
The response object expects a headers= argument, and otherwise resets the headers dict to {} instead of reading any headers that might have been set by the previous code.
Is a workaround, but would be nicer if the Response object copies the headers from the originating request's response object.