http://search.cpan.org/dist/File-MMagic-XS/
So is this module something that should be implemented in a
PerlTypeHandler [1]?
I gathered from Jeff's question that he would be determining the file
from the PerlResponseHandler, so that's where he would need to set the
Content-Type. determining the file earlier (like from a
PerlTransHandler) would mean he could set $r->filename at let Apache
handle both Content-Type setting and response sending, just like John
described.
btw, well done John, remembering to set finfo :)
No one had their hands up in Geoff's testing talks
when he asked about who has written a PerlTypeHandler from the two I've
been to
well, Matt's hand went up at YAPC, but he and I are the only ones that
have PerlTypeHandlers for mp1 on CPAN IIRC. maybe doug has one from his
book examples as well :)
, but iirc he was referring to mp1 when he asked that.
yes.
From
looking at the HTTP Handlers section of the docs, PerlTypeHandler runs
before the PerlResponseHandler, so it seems that the type could be
dependent on the response.
yes. the MIME-setting phase is generally for setting the MIME type
under one of several conditions
- the request maps to a known file on disk, which can then be
examined to determine the MIME type
- directives like ForceType and DefaultType
- custom handlers that want to set a Content-Type header based on
other criteria, like the URI
of course, content handlers (like the PerlResponseHandler) can always
override what mod_mime chooses, which is what we see most of the time with
$r->send_http_headers('text/html');
or
$r->content_type('text/html');
what it boils down to is what type of mod_perl application you have. if
you can let apache figure out the content-type itself (via $r->filename)
then that's the best approach. if you're reading a "file" from a
database or something then you'll need to use the response phase.
does that kinda clear things up?
--Geoff