[mod_python] Sending back headers with 4xx responses

Nic James Ferrier nferrier at tapsellferrier.co.uk
Wed May 31 11:41:32 EDT 2006


"Deron Meranda" <deron.meranda at gmail.com> writes:

> I don't know if this is mod_python or perhaps just an Apache
> limitation, but is it possible to send back specific HTTP
> headers for any 4xx response codes?
>
> In particular, I'm trying to send a 416 "Requested Range Not
> Satisfiable", as well as a Content-Ranges header, but the
> header is never sent back to the user agent.  As per the
> RFC 2616 spec section 14.16:
>
>    "A server sending a response with status code 416
>     (Requested range not satisfiable) SHOULD include a
>     Content-Range field with a byte-range-resp-spec of "*".
>     The instance-length specifies the current length of the
>     selected resource."
>
> Granted, it's a SHOULD rather than a MUST, but is it
> even possible with Apache/mod_python?  BTW, sending
> headers works fine for any 2xx or 3xx reponses.
>
> Here's a minimal handler which demonstrates this.
>
> from mod_python import apache
> def handler(req):
>     req.headers_out['Content-Range'] = "*/10000"
>     return apache.HTTP_RANGE_NOT_SATISFIABLE

You have to raise these.

For example:

    if status >= 200 and status < 300:
        return apache.OK
    else:
        raise apache.SERVER_RETURN, status


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   for all your tapsell ferrier needs


More information about the Mod_python mailing list