[mod_python] setting content_type intelligently

Daniel J. Popowich dpopowich at mtrsd.k12.ma.us
Wed Jan 14 10:10:57 EST 2004


Manfred Stienstra writes:
> On Tue, 2004-01-13 at 16:40, Daniel J. Popowich wrote:
> >    1.  What does mod_python/apache do if content_type is not set by a
> >        handler?  Does it default to text/plain?
> 
> It defaults to the default Apache mimetype.
> 
> >    2.  I'm looking for an intelligent means of setting the
> >        content_type.  I know I can use mimetypes.guess_type(), but
> >        that is based only on the file's extension.  Apache does more
> >        than that, eg, if 'foo.gif' was named 'foo' apache still
> >        determines the content type correctly as image/gif.  Is there a
> >        way to tap into apache's content_type determination?
> 
> Apache uses the same resolution as the 'file' command on *nix, it uses a
> file with rules (/etc/apache*/mime.types) to resolve the mimetype. I'm
> not sure if there is a python frontend for this.

Thanks, after reading that I discovered mod_mime and mod_mime_magic.
It's not clear to me how to tap into those.  Anyone know?

Meanwhile I guess I'm stuck with mimetypes.guess_type() or moving my
app into a <Directory ...> directive.

Dan




More information about the Mod_python mailing list