[mod_python] set the content-type

Graham Dumpleton grahamd at dscpl.com.au
Sat Nov 11 20:37:02 EST 2006


On 11/11/2006, at 12:36 AM, julien.coron at free.fr wrote:

> Hi,
>
> Someone can explain me why the following line works well:
>
> request.content_type = 'text/html'
>
>
> But this not:
>
> request.headers_out.add("Content-Type","text/html")
>
>
> and seems to be "httpd/unix-directory"...

Because that is how Apache works. Specifically, the default header  
output
filter for the HTTP protocol in Apache takes the value of  
req.content_type
and saves it in the header as 'Content-Type' header.

Thus, if you set the header yourself, it will be overridden by  
whatever the
value of req.content_type is. In the above example, the request URL
matched to a directory and therefore the inbound content type as  
determined
by Apache was 'httpd/unix-directory'. Note that it even produces this  
on Win32
because of the heritage of Apache being written for UNIX first.

In summary, if you need to set the outbound content type use  
req.content_type.

Graham


More information about the Mod_python mailing list