[mod_python] Sending back headers with 4xx responses

Deron Meranda deron.meranda at gmail.com
Wed May 31 11:28:31 EDT 2006


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

Any ideas?
-- 
Deron Meranda


More information about the Mod_python mailing list