<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Plack::MIME;
use strict;

# stolen from rack.mime.rb
our $MIME_TYPES = {
    ".3gp"     =&gt; "video/3gpp",
    ".a"       =&gt; "application/octet-stream",
    ".ai"      =&gt; "application/postscript",
    ".aif"     =&gt; "audio/x-aiff",
    ".aiff"    =&gt; "audio/x-aiff",
    ".apk"     =&gt; "application/vnd.android.package-archive",
    ".asc"     =&gt; "application/pgp-signature",
    ".asf"     =&gt; "video/x-ms-asf",
    ".asm"     =&gt; "text/x-asm",
    ".asx"     =&gt; "video/x-ms-asf",
    ".atom"    =&gt; "application/atom+xml",
    ".au"      =&gt; "audio/basic",
    ".avi"     =&gt; "video/x-msvideo",
    ".bat"     =&gt; "application/x-msdownload",
    ".bin"     =&gt; "application/octet-stream",
    ".bmp"     =&gt; "image/bmp",
    ".bz2"     =&gt; "application/x-bzip2",
    ".c"       =&gt; "text/x-c",
    ".cab"     =&gt; "application/vnd.ms-cab-compressed",
    ".cc"      =&gt; "text/x-c",
    ".chm"     =&gt; "application/vnd.ms-htmlhelp",
    ".class"   =&gt; "application/octet-stream",
    ".com"     =&gt; "application/x-msdownload",
    ".conf"    =&gt; "text/plain",
    ".cpp"     =&gt; "text/x-c",
    ".crt"     =&gt; "application/x-x509-ca-cert",
    ".css"     =&gt; "text/css",
    ".csv"     =&gt; "text/csv",
    ".cxx"     =&gt; "text/x-c",
    ".deb"     =&gt; "application/x-debian-package",
    ".der"     =&gt; "application/x-x509-ca-cert",
    ".diff"    =&gt; "text/x-diff",
    ".djv"     =&gt; "image/vnd.djvu",
    ".djvu"    =&gt; "image/vnd.djvu",
    ".dll"     =&gt; "application/x-msdownload",
    ".dmg"     =&gt; "application/octet-stream",
    ".doc"     =&gt; "application/msword",
    ".dot"     =&gt; "application/msword",
    ".dtd"     =&gt; "application/xml-dtd",
    ".dvi"     =&gt; "application/x-dvi",
    ".ear"     =&gt; "application/java-archive",
    ".eml"     =&gt; "message/rfc822",
    ".eps"     =&gt; "application/postscript",
    ".exe"     =&gt; "application/x-msdownload",
    ".f"       =&gt; "text/x-fortran",
    ".f77"     =&gt; "text/x-fortran",
    ".f90"     =&gt; "text/x-fortran",
    ".flv"     =&gt; "video/x-flv",
    ".for"     =&gt; "text/x-fortran",
    ".gem"     =&gt; "application/octet-stream",
    ".gemspec" =&gt; "text/x-script.ruby",
    ".gif"     =&gt; "image/gif",
    ".gz"      =&gt; "application/x-gzip",
    ".h"       =&gt; "text/x-c",
    ".hh"      =&gt; "text/x-c",
    ".htm"     =&gt; "text/html",
    ".html"    =&gt; "text/html",
    ".ico"     =&gt; "image/vnd.microsoft.icon",
    ".ics"     =&gt; "text/calendar",
    ".ifb"     =&gt; "text/calendar",
    ".iso"     =&gt; "application/octet-stream",
    ".jar"     =&gt; "application/java-archive",
    ".java"    =&gt; "text/x-java-source",
    ".jnlp"    =&gt; "application/x-java-jnlp-file",
    ".jpeg"    =&gt; "image/jpeg",
    ".jpg"     =&gt; "image/jpeg",
    ".js"      =&gt; "application/javascript",
    ".json"    =&gt; "application/json",
    ".log"     =&gt; "text/plain",
    ".m3u"     =&gt; "audio/x-mpegurl",
    ".m4v"     =&gt; "video/mp4",
    ".man"     =&gt; "text/troff",
    ".manifest"=&gt; "text/cache-manifest",
    ".mathml"  =&gt; "application/mathml+xml",
    ".mbox"    =&gt; "application/mbox",
    ".mdoc"    =&gt; "text/troff",
    ".me"      =&gt; "text/troff",
    ".mid"     =&gt; "audio/midi",
    ".midi"    =&gt; "audio/midi",
    ".mime"    =&gt; "message/rfc822",
    ".mml"     =&gt; "application/mathml+xml",
    ".mng"     =&gt; "video/x-mng",
    ".mov"     =&gt; "video/quicktime",
    ".mp3"     =&gt; "audio/mpeg",
    ".mp4"     =&gt; "video/mp4",
    ".mp4v"    =&gt; "video/mp4",
    ".mpeg"    =&gt; "video/mpeg",
    ".mpg"     =&gt; "video/mpeg",
    ".ms"      =&gt; "text/troff",
    ".msi"     =&gt; "application/x-msdownload",
    ".odp"     =&gt; "application/vnd.oasis.opendocument.presentation",
    ".ods"     =&gt; "application/vnd.oasis.opendocument.spreadsheet",
    ".odt"     =&gt; "application/vnd.oasis.opendocument.text",
    ".ogg"     =&gt; "application/ogg",
    ".ogv"     =&gt; "video/ogg",
    ".p"       =&gt; "text/x-pascal",
    ".pas"     =&gt; "text/x-pascal",
    ".pbm"     =&gt; "image/x-portable-bitmap",
    ".pdf"     =&gt; "application/pdf",
    ".pem"     =&gt; "application/x-x509-ca-cert",
    ".pgm"     =&gt; "image/x-portable-graymap",
    ".pgp"     =&gt; "application/pgp-encrypted",
    ".pkg"     =&gt; "application/octet-stream",
    ".pl"      =&gt; "text/x-script.perl",
    ".pm"      =&gt; "text/x-script.perl-module",
    ".png"     =&gt; "image/png",
    ".pnm"     =&gt; "image/x-portable-anymap",
    ".ppm"     =&gt; "image/x-portable-pixmap",
    ".pps"     =&gt; "application/vnd.ms-powerpoint",
    ".ppt"     =&gt; "application/vnd.ms-powerpoint",
    ".ps"      =&gt; "application/postscript",
    ".psd"     =&gt; "image/vnd.adobe.photoshop",
    ".py"      =&gt; "text/x-script.python",
    ".qt"      =&gt; "video/quicktime",
    ".ra"      =&gt; "audio/x-pn-realaudio",
    ".rake"    =&gt; "text/x-script.ruby",
    ".ram"     =&gt; "audio/x-pn-realaudio",
    ".rar"     =&gt; "application/x-rar-compressed",
    ".rb"      =&gt; "text/x-script.ruby",
    ".rdf"     =&gt; "application/rdf+xml",
    ".roff"    =&gt; "text/troff",
    ".rpm"     =&gt; "application/x-redhat-package-manager",
    ".rss"     =&gt; "application/rss+xml",
    ".rtf"     =&gt; "application/rtf",
    ".ru"      =&gt; "text/x-script.ruby",
    ".s"       =&gt; "text/x-asm",
    ".sgm"     =&gt; "text/sgml",
    ".sgml"    =&gt; "text/sgml",
    ".sh"      =&gt; "application/x-sh",
    ".sig"     =&gt; "application/pgp-signature",
    ".snd"     =&gt; "audio/basic",
    ".so"      =&gt; "application/octet-stream",
    ".svg"     =&gt; "image/svg+xml",
    ".svgz"    =&gt; "image/svg+xml",
    ".swf"     =&gt; "application/x-shockwave-flash",
    ".t"       =&gt; "text/troff",
    ".tar"     =&gt; "application/x-tar",
    ".tbz"     =&gt; "application/x-bzip-compressed-tar",
    ".tcl"     =&gt; "application/x-tcl",
    ".tex"     =&gt; "application/x-tex",
    ".texi"    =&gt; "application/x-texinfo",
    ".texinfo" =&gt; "application/x-texinfo",
    ".text"    =&gt; "text/plain",
    ".tif"     =&gt; "image/tiff",
    ".tiff"    =&gt; "image/tiff",
    ".torrent" =&gt; "application/x-bittorrent",
    ".tr"      =&gt; "text/troff",
    ".txt"     =&gt; "text/plain",
    ".vcf"     =&gt; "text/x-vcard",
    ".vcs"     =&gt; "text/x-vcalendar",
    ".vrml"    =&gt; "model/vrml",
    ".war"     =&gt; "application/java-archive",
    ".wav"     =&gt; "audio/x-wav",
    ".webm"    =&gt; "video/webm",
    ".wma"     =&gt; "audio/x-ms-wma",
    ".wmv"     =&gt; "video/x-ms-wmv",
    ".wmx"     =&gt; "video/x-ms-wmx",
    ".woff"    =&gt; "application/font-woff",
    ".wrl"     =&gt; "model/vrml",
    ".wsdl"    =&gt; "application/wsdl+xml",
    ".xbm"     =&gt; "image/x-xbitmap",
    ".xhtml"   =&gt; "application/xhtml+xml",
    ".xls"     =&gt; "application/vnd.ms-excel",
    ".xml"     =&gt; "application/xml",
    ".xpm"     =&gt; "image/x-xpixmap",
    ".xsl"     =&gt; "application/xml",
    ".xslt"    =&gt; "application/xslt+xml",
    ".yaml"    =&gt; "text/yaml",
    ".yml"     =&gt; "text/yaml",
    ".zip"     =&gt; "application/zip",
};

my $fallback = sub { };

sub mime_type {
    my($class, $file) = @_;
    $file =~ /(\.[a-zA-Z0-9]+)$/ or return;
    $MIME_TYPES-&gt;{lc $1} || $fallback-&gt;(lc $1);
}

sub add_type {
    my $class = shift;
    while (my($ext, $type) = splice @_, 0, 2) {
        $MIME_TYPES-&gt;{lc $ext} = $type;
    }
}

sub set_fallback {
    my($class, $cb) = @_;
    $fallback = $cb;
}

1;

__END__

=head1 NAME

Plack::MIME - MIME type registry

=head1 SYNOPSIS

  use Plack::MIME;

  my $mime = Plack::MIME-&gt;mime_type(".png"); # image/png

  # register new type(s)
  Plack::MIME-&gt;add_type(".foo" =&gt; "application/x-foo");

  # Use MIME::Types as a fallback
  use MIME::Types 'by_suffix';
  Plack::MIME-&gt;set_fallback(sub { (by_suffix $_[0])[0] });

=head1 DESCRIPTION

Plack::MIME is a simple MIME type registry for Plack applications. The
selection of MIME types is based on Rack's Rack::Mime module.

=head1 SEE ALSO

L&lt;Rack::Mime|https://github.com/rack/rack/blob/master/lib/rack/mime.rb&gt; L&lt;MIME::Types&gt;

=cut


</pre></body></html>