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

Petri Lehtinen report at bugs.python.org
Sun Jul 3 21:45:58 CEST 2011


Petri Lehtinen <petri at digip.org> added the comment:

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 

    HTTP/1.1 123 FOOBAR\r\n

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.)

----------
nosy: +petri.lehtinen
resolution:  -> invalid

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


More information about the Python-bugs-list mailing list