#!/usr/bin/perl -w
my
%default_types
= (
'html'
=>
'text/html'
,
'htm'
=>
'text/html'
,
'txt'
=>
'text/plain'
,
'gif'
=>
'image/gif'
,
'jpeg'
=>
'image/jpeg'
,
'jpg'
=>
'image/jpeg'
,
'png'
=>
'image/png'
,
'tiff'
=>
'image/tiff'
,
'ico'
=>
'image/x-icon'
,
'css'
=>
'text/css'
,
'csv'
=>
'text/csv'
,
'rtf'
=>
'text/rtf'
,
'xml'
=>
'text/xml'
,
'mpg'
=>
'video/mpeg'
,
'avi'
=>
'application/octet-stream'
,
'eml'
=>
'message/rfc822'
,
'mp2'
=>
'audio/mpeg'
,
'mp3'
=>
'audio/mpeg'
,
'mp4'
=>
'audio/mp4'
,
'js'
=>
'application/ecmascript'
,
'doc'
=>
'application/msword'
,
'gz'
=>
'application/octet-stream'
,
'xhtml'
=>
'application/xhtml+xml'
,
'dtd'
=>
'application/xml-dtd'
,
'xls'
=>
'application/ms-excel'
,
'ppt'
=>
'application/ms-powerpoint'
,
'pps'
=>
'application/ms-powerpoint'
,
'rpm'
=>
'application/octet-stream'
,
'pdf'
=>
'application/pdf'
,
'ps'
=>
'application/postscript'
,
'rdf'
=>
'application/rdf+xml'
,
'smil'
=>
'application/smil+xml'
,
'#default'
=>
'text/html'
,
);
sub
conf_MimeMap {
my
(
$self
,
$ext
,
$type
) =
@_
;
$self
->config(
'MimeMap'
,{
%default_types
})
unless
$self
->config(
'MimeMap'
);
$ext
=~ s/^\.//;
$self
->config(
'MimeMap'
)->{
$ext
} =
$type
;
return
();
}
sub
hook_mime_map {
my
(
$self
,
$hd
,
$filename
) =
@_
;
my
$map
=
$self
->config(
'MimeMap'
) || \
%default_types
;
$filename
=~ s/.*\///;
my
@parts
=
split
(/\./,
$filename
);
my
$uno
= 0;
while
(
@parts
) {
my
$name
=
join
(
'.'
,
@parts
);
if
(
exists
(
$map
->{
$name
})) {
$hd
->mime_type(
$map
->{
$name
});
return
OK;
}
shift
@parts
;
}
$hd
->mime_type(
$map
->{
'#default'
});
return
DECLINED;
}