fetchItem: improved mime type guessing.

Strip a fragment like `?#iefix` from the extension before doing
the mime lookup.
This commit is contained in:
John MacFarlane 2014-08-02 16:32:11 -07:00
parent 1d137fbed6
commit 85ff3c5771

View file

@ -775,12 +775,13 @@ fetchItem sourceURL s =
Nothing -> openURL s' -- will throw error
(Nothing, _) -> E.try readLocalFile -- get from local file system
where readLocalFile = do
let mime = case takeExtension s of
".gz" -> getMimeType $ dropExtension s
x -> getMimeType x
cont <- BS.readFile $ unEscapeString $ dropFragmentAndQuery s
cont <- BS.readFile fp
return (cont, mime)
dropFragmentAndQuery = takeWhile (\c -> c /= '?' && c /= '#')
fp = unEscapeString $ dropFragmentAndQuery s
mime = case takeExtension fp of
".gz" -> getMimeType $ dropExtension fp
x -> getMimeType x
ensureEscaped = escapeURIString isAllowedInURI
-- | Like 'fetchItem', but also looks for items in a 'MediaBag'.