Ignore:
Timestamp:
Apr 10, 2017, 4:56:03 AM (5 years ago)
Author:
andersk
Message:
Improve Content-Type and Content-Encoding headers

Since Chrome has started decompressing tarballs served with
Content-Encoding: x-gzip on download, we don’t want to be sending that
by default.

Remove all the custom AddType and AddEncoding directives from
httpd.conf (let it pick up MIME types from /etc/mime.types).  Do not
set Content-Encoding in static-cat, and fix some of the hard-coded
MIME types there.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/common/oursrc/scripts-static-cat/StaticCat.hs

    r2796 r2837  
    2323import System.Posix.Handle
    2424
    25 encodings :: M.Map String String
    26 encodings = M.fromList [
    27              (".bz2", "bzip2"),
    28              (".gz", "gzip"),
    29              (".z", "compress")
    30             ]
    31 
    3225types :: M.Map String String
    3326types = M.fromList [
     
    4942         (".jpeg", "image/jpeg"),
    5043         (".jpg", "image/jpeg"),
    51          (".js", "application/x-javascript"),
     44         (".js", "application/javascript"),
    5245         (".mid", "audio/midi"),
    5346         (".midi", "audio/midi"),
     
    8881         (".swf", "application/x-shockwave-flash"),
    8982         (".tar", "application/x-tar"),
    90          (".tgz", "application/x-gzip"),
     83         (".tgz", "application/gzip"),
    9184         (".tif", "image/tiff"),
    9285         (".tiff", "image/tiff"),
     
    109102         (".xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template"),
    110103         (".xml", "text/xml"),
    111          (".xsl", "text/xml"),
     104         (".xsl", "application/xslt+xml"),
    112105         (".zip", "application/zip")
    113106        ]
     
    126119
    127120checkExtension :: FilePath -> CGI ()
    128 checkExtension file = do
    129   let (base, ext) = splitExtension file
    130   ext' <- case M.lookup (map toLower ext) encodings of
    131             Nothing -> return ext
    132             Just e -> do
    133               setHeader "Content-Encoding" e
    134               return $ takeExtension base
    135 
    136   case M.lookup (map toLower ext') types of
     121checkExtension file =
     122  case M.lookup (map toLower (takeExtension file)) types of
    137123    Nothing -> throw Forbidden
    138124    Just t -> setHeader "Content-Type" t
Note: See TracChangeset for help on using the changeset viewer.