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

Yoav Weiss report at bugs.python.org
Mon Jul 4 12:52:45 CEST 2011


Yoav Weiss <yoav.weiss.fr at gmail.com> added the comment:

Thanks for correcting me. I guess I assumed that the "message" variable is
an HTTPMessage.
Is send_response documented somewhere? I failed to find a reference.

On Sun, Jul 3, 2011 at 9:45 PM, Petri Lehtinen <report at bugs.python.org>wrote:

>
> 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>
> _______________________________________
>

----------
Added file: http://bugs.python.org/file22565/unnamed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12439>
_______________________________________
-------------- next part --------------
Thanks for correcting me. I guess I assumed that the &quot;message&quot; variable is an HTTPMessage.<div>Is send_response documented somewhere? I failed to find a reference.</div><div><br></div><div><br><div class="gmail_quote">
On Sun, Jul 3, 2011 at 9:45 PM, Petri Lehtinen <span dir="ltr">&lt;<a href="mailto:report at bugs.python.org">report at bugs.python.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Petri Lehtinen &lt;<a href="mailto:petri at digip.org">petri at digip.org</a>&gt; added the comment:<br>
<br>
It seems to me that you&#39;re indeed misusing it.<br>
<br>
The correct way would be something like this (assuming response is a HTTPResponse object from httplib):<br>
<br>
self.send_response(response.status)<br>
for name, value in response.getheaders():<br>
    self.send_header(name, value)<br>
self.end_headers()<br>
<br>
This is because send_response&#39;s second argument is the HTTP&#39;s &quot;reason&quot; field, i.e. invoking:<br>
<br>
    self.send_response(123, &#39;FOOBAR&#39;)<br>
<br>
results in<br>
<br>
    HTTP/1.1 123 FOOBAR\r\n<br>
<br>
to be sent, followed by &quot;Server&quot; and &quot;Date&quot; headers. The second argument is not meant to be used for sending headers.<br>
<br>
(When the second argument is omitted, a standard reason for the given status code is used.)<br>
<br>
----------<br>
nosy: +petri.lehtinen<br>
resolution:  -&gt; invalid<br>
<div><div></div><div class="h5"><br>
_______________________________________<br>
Python tracker &lt;<a href="mailto:report at bugs.python.org">report at bugs.python.org</a>&gt;<br>
&lt;<a href="http://bugs.python.org/issue12439" target="_blank">http://bugs.python.org/issue12439</a>&gt;<br>
_______________________________________<br>
</div></div></blockquote></div><br></div>


More information about the Python-bugs-list mailing list