[mod_python] setting content_type intelligently

Michael C. Neel neel at mediapulse.com
Thu Feb 5 12:01:38 EST 2004


Well, imho when things get painful it's usally time to consider
something's not right =).

As a hail mary play, I believe there is a phase of the request where
apache goes searching the disk for the file, separate from the content
handling phase.  This is where DocumentRoot, Alias, ScriptAlias, etc are
all handled.  You could handle this yourself, and when you image request
comes in, set the required pieces of the request data to state the
location of the image on disk.  The your content handler would return
apache.DECLINED, and then apache mime magic would take over.

FYI apache's mime handling is just extension based.  The mapping is
either defined in the conf files (something called mime.conf fulle of
AddTypes) or can be told to use the /etc/mime.types file.  If your
concern is images only, python's stdlib imghdr module, which can tell
the image type by looking at the first few bytes of the file, and works
for the images files that would be used in a web page.  If you also have
other data, such as pdf's, then best to go with mime.types.  If your
apache is using /etc/mime.types, then you can have mimetypes also use
that file.  See what your mimetypes.knownfiles are, and run
mimetypes.init() to load the files listed (if they exist).

let me know if any of the above pan out,
mike

> I'm aware I can (technically) return apache.DECLINED, it's just that
> it doesn't work for me because the images are outside of DocumentRoot.
> 
...
> For cultural reasons this is not feasible for this app.  My users
> demand their images be "near" their docs.  Oh, tho I've tried to press
> the issue.



More information about the Mod_python mailing list