New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BaseHTTPServer's send_reponse adds extra "\r\n" when using HTTPMessage in input #56648
Comments
I'm using BaseHTTPServer's send_response (from within a class that inherits BaseHTTPRequestHandler) with the following: self.send_response(response.code, response.headers)
self.end_headers()
self.wfile.write(content)
self.wfile.flush()
When response is a httplib's HTTPResponse object, and its headers inherits from rfc822.Message. What I see is that message is printed as is, including all the headers trailing "\r\n", after which the send_response method (BaseHTTPServer.py:381) adds another "\r\n". Am I misusing BaseHTTPServer? If not, this is a bug and "\r\n" should be removed from line 381, or added only after a check that shows they are not already there at the headers end, or in case there are no input headers. |
It seems to me that you're indeed misusing it. The correct way would be something like this (assuming response is a HTTPResponse object from httplib): self.send_response(response.status)
for name, value in response.getheaders():
self.send_header(name, value)
self.end_headers() This is because send_response's second argument is the HTTP's "reason" field, i.e. invoking: self.send_response(123, 'FOOBAR') results in
to be sent, followed by "Server" and "Date" headers. The second argument is not meant to be used for sending headers. (When the second argument is omitted, a standard reason for the given status code is used.) |
Thanks for correcting me. I guess I assumed that the "message" variable is On Sun, Jul 3, 2011 at 9:45 PM, Petri Lehtinen <report@bugs.python.org>wrote:
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: