X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debbugs%2FLibravatar.pm;fp=Debbugs%2FLibravatar.pm;h=ca9c035df350bd48c6e59b80d0c8316690c21143;hb=5f45bb2288c4440f63b67da872bc08633b443fae;hp=ed36b91d23f48033ca6524beedb226740b80a738;hpb=9ba439f0dec2d3980de21b01d5f335a9d213158f;p=debbugs.git diff --git a/Debbugs/Libravatar.pm b/Debbugs/Libravatar.pm index ed36b91..ca9c035 100644 --- a/Debbugs/Libravatar.pm +++ b/Debbugs/Libravatar.pm @@ -41,6 +41,8 @@ use Debbugs::CGI qw(cgi_parameters); use Digest::MD5 qw(md5_hex); use LWP::UserAgent; use File::Temp qw(tempfile); +use File::LibMagic; +use Cwd qw(abs_path); use Carp; @@ -263,7 +265,7 @@ sub handler { serve_cache_mod_perl($cache_location,$r); return Apache2::Const::DECLINED(); } - $cache_location = retreive_libravatar(location => $cache_location, + $cache_location = retrieve_libravatar(location => $cache_location, email => $email, ); if (not defined $cache_location) { @@ -277,12 +279,21 @@ sub handler { } + +our $magic; + sub serve_cache_mod_perl { my ($cache_location,$r) = @_; if (not defined $cache_location or not length $cache_location) { # serve the default image $cache_location = $config{libravatar_default_image}; } + $magic = File::LibMagic->new() if not defined $magic; + + return Apache2::Const::DECLINED() if not defined $magic; + + $r->content_type($magic->checktype_filename(abs_path($cache_location))); + $r->filename($cache_location); $r->path_info(''); $r->finfo(APR::Finfo::stat($cache_location, APR::Const::FINFO_NORM(), $r->pool));