Re: Simple Proposal for setting HTTP headers

On 08/08/13 10:53, Robin Berjon wrote:
> On 08/08/2013 00:32 , James Graham wrote:
>> So, having looked at the code, and talked to the mozbase people, it
>> seems like this might not be the easiest path; it's based on
>> SimpleHTTPServer, which wants you to provide a response code, headers
>> dict and body string. That's just not flexibility for our purposes, so
>> it would be necessary to work around the existing behaviour to get what
>> we want.
>
> Actually, as demonstrated by gsnedders, you can overwride the
> SimpleHTTPServer behaviour to get asis-like control. See:
>
> http://hg.gsnedders.com/http-parsing/file/bbab4a6298d7/tests/response/response.py
>
>
> So it ought to be possible to start from there.

Specifically, SimpleHTTPServer, through its superclass, has a wfile (a 
file-like object of the socket) attribute. All the functions it provides 
are just an abstraction around this: you can perfectly well just write 
entire HTTP responses (including the response line) to the socket in the 
do_GET, do_HEAD, etc. methods. (Depending on quite what you need, you 
may be better off just inheriting from BaseHTTPServer directly.)


-- 
Geoffrey Sneddon — Opera Software
<http://gsnedders.com>
<http://opera.com>

Received on Thursday, 8 August 2013 12:16:24 UTC