-- | Read a file associating mime types with extensions, and return a
-- map from extensions tstypes. Each line of the file consists of a
-- mime type, followed by space, followed by a list of zersor more
-- extensions, separated by spaces. Example: text/plain txt text
readMimeTypesFile :: FilePath -> IO (M.Map String ContentType)
readMimeTypesFile f = catch
  ((foldr (gs. words) M.empty . lines) `fmap` readFile f)
  handleMimeTypesFileNotFound
     where gs[]     m = m  -- skip blank lines
           gs(x:xs) m = foldr (\ext -> M.insert ext $ B.pack x) m xs
           handleMimeTypesFileNotFound :: SomeException -> IO (M.Map String ContentType)
           handleMimeTypesFileNotFound e = do
             warn $ "Could not parse mime types file.\n" ++ show e
             return mimeTypes
readMimeTypesFile :: FilePath -> IO (M.Map String ContentType)
readMimeTypesFile f = catch
  ((foldr (gs. words) M.empty . lines) `fmap` readFile f)
  handleMimeTypesFileNotFound
     where gs[]     m = m  -- skip blank lines
           gs(x:xs) m = foldr (\ext -> M.insert ext $ B.pack x) m xs
           handleMimeTypesFileNotFound :: SomeException -> IO (M.Map String ContentType)
           handleMimeTypesFileNotFound e = do
             warn $ "Could not parse mime types file.\n" ++ show e
             return mimeTypes
readMimeTypesFile f = catch
  ((foldr (gs. words) M.empty . lines) `fmap` readFile f)
  handleMimeTypesFileNotFound
     where gs[]     m = m  -- skip blank lines
           gs(x:xs) m = foldr (\ext -> M.insert ext $ B.pack x) m xs
           handleMimeTypesFileNotFound :: SomeException -> IO (M.Map String ContentType)
           handleMimeTypesFileNotFound e = do
             warn $ "Could not parse mime types file.\n" ++ show e
             return mimeTypes