[issue12439] BaseHTTPServer's send_reponse adds extra "\r\n" when using HTTPMessage in input

Yoav Weiss report at bugs.python.org
Wed Jun 29 11:35:25 CEST 2011


New submission from Yoav Weiss <yoav.weiss.fr at gmail.com>:

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".
Then send_response adds the "Server" and "Date" headers.
Since the headers before Server & Date include "\r\n\r\n", Date & server are considered by the browser as the content.

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.

----------
components: Library (Lib)
messages: 139401
nosy: Yoav.Weiss
priority: normal
severity: normal
status: open
title: BaseHTTPServer's send_reponse adds extra "\r\n" when using HTTPMessage in input
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12439>
_______________________________________


More information about the Python-bugs-list mailing list