]> andersk Git - scripts-static-cat.git/commitdiff
Support lots of new extensions.
authorAnders Kaseorg <andersk@mit.edu>
Mon, 15 Mar 2010 06:41:35 +0000 (02:41 -0400)
committerAnders Kaseorg <andersk@mit.edu>
Mon, 15 Mar 2010 06:41:35 +0000 (02:41 -0400)
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
StaticCat.hs

index be7fbe0ceccb1d4fd4b79221808c58e3992246ea..baa509419ef70543f055a141dcc696f61444bb5a 100644 (file)
@@ -5,6 +5,7 @@ import Control.Applicative
 import Control.Exception
 import Control.Monad
 import qualified Data.ByteString.Lazy as B
+import Data.Char
 import Data.Dynamic
 import qualified Data.Map as M
 import Data.Time.Clock.POSIX
@@ -20,13 +21,50 @@ import System.Posix.Handle
 
 encodings :: M.Map String String
 encodings = M.fromList [
+             (".bz2", "bzip2"),
              (".gz", "gzip"),
-             (".bz2", "bzip2")
+             (".z", "compress")
             ]
 
 types :: M.Map String String
 types = M.fromList [
-         (".html", "text/html")
+         (".avi", "video/x-msvideo"),
+         (".css", "text/css"),
+         (".doc", "application/msword"),
+         (".gif", "image/gif"),
+         (".htm", "text/html"),
+         (".html", "text/html"),
+         (".ico", "image/vnd.microsoft.icon"),
+         (".il", "application/octet-stream"),
+         (".jar", "application/java-archive"),
+         (".jpeg", "image/jpeg"),
+         (".jpg", "image/jpeg"),
+         (".js", "application/x-javascript"),
+         (".mid", "audio/midi"),
+         (".midi", "audio/midi"),
+         (".mov", "video/quicktime"),
+         (".mp3", "audio/mpeg"),
+         (".mpeg", "video/mpeg"),
+         (".mpg", "video/mpeg"),
+         (".pdf", "application/pdf"),
+         (".png", "image/png"),
+         (".ppt", "application/vnd.ms-powerpoint"),
+         (".ps", "application/postscript"),
+         (".svg", "image/svg+xml"),
+         (".swf", "application/x-shockwave-flash"),
+         (".tar", "application/x-tar"),
+         (".tgz", "application/x-gzip"),
+         (".tif", "image/tiff"),
+         (".tiff", "image/tiff"),
+         (".wav", "audio/x-wav"),
+         (".wmv", "video/x-ms-wmv"),
+         (".xaml", "application/xaml+xml"),
+         (".xap", "application/x-silverlight-app"),
+         (".xhtml", "application/xhtml+xml"),
+         (".xls", "application/vnd.ms-excel"),
+         (".xml", "text/xml"),
+         (".xsl", "text/xml"),
+         (".zip", "application/zip")
         ]
 
 throwExceptionCGI :: Exception e => e -> CGI a
@@ -53,13 +91,13 @@ outputMyError BadRange = outputError 416 "Requested Range Not Satisfiable" []
 checkExtension :: FilePath -> CGI ()
 checkExtension file = do
   let (base, ext) = splitExtension file
-  ext' <- case M.lookup ext encodings of
+  ext' <- case M.lookup (map toLower ext) encodings of
             Nothing -> return ext
             Just e -> do
               setHeader "Content-Encoding" e
               return $ takeExtension base
 
-  case M.lookup ext' types of
+  case M.lookup (map toLower ext') types of
     Nothing -> throwExceptionCGI Forbidden
     Just t -> setHeader "Content-Type" t
 
This page took 0.787771 seconds and 5 git commands to generate.