[mod_python] http response code

Ricardo Rocha ricardo.rocha at cern.ch
Tue Aug 22 06:28:29 EDT 2006


Thanks (Graham and Richard). This works fine.

I've removed the ErrorDocument from the apache2 config too.

Ricardo

Graham Dumpleton wrote:
> 
> On 22/08/2006, at 5:25 PM, Ricardo Rocha wrote:
> 
>> Hi all.
>>
>> I'm not really sure if this is a mod_python or apache question, but 
>> i'll give it a try anyway. My setup is Apache 2.0.55 with mod_python 3.2.
>>
>> I've been looking for a way to send additional error messages along 
>> with the HTTP error codes. The first thing i did was to remove the 
>> default apache error messages by adding the following directives to 
>> the apache config:
>> ErrorDocument 400 " "
>> ErrorDocument 401 " "
>> ErrorDocument 404 " "
>> ErrorDocument 406 " "
>> ErrorDocument 409 " "
>> ErrorDocument 500 " "
>> ErrorDocument 501 " "
>>
>> Then i was hoping that returning the proper HTTP code from the handler 
>> would do it... and it does, as long as i haven't written anything back 
>> to the client before.
>>
>> If i do write something back inside the handler, if i try to return 
>> apache.HTTP_BAD_REQUEST (for example), it will always give a 200 
>> HTTP_OK code back to the client, along with the response text.
>>
>> Is there a way to overcome this and have both a response being written 
>> back and a specific HTTP code being returned?
> 
> Use:
> 
>   def handler(req):
>     req.status = apache.HTTP_BAD_REQUEST
>     req.content_type = 'text/html'
>     req.write(....)
>     return apache.DONE
> 
> Setting req.status and req.content_type must be done before first write as
> you found at.
> 
> Setting req.status and returning apache.DONE is key as that is what tells
> Apache not to format its own error response.
> 
> Graham
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2678 bytes
Desc: S/MIME Cryptographic Signature
Url : http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20060822/05121f4c/smime.bin


More information about the Mod_python mailing list