Skip to content

Instantly share code, notes, and snippets.

Created February 21, 2013 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/5005479 to your computer and use it in GitHub Desktop.
Save anonymous/5005479 to your computer and use it in GitHub Desktop.
-- | Fetch the contents of a uri, which must be an ascii string.
-- Redirects, authentication, https: and file: uris are supported.
readUri :: Manager -> String -> Opts -> IO String
readUri manager s opts =
case parseURI' s of
Just URI{uriScheme="file:",uriPath=f} -> readFeedFile f
Just _ -> do
r <- parseUrl s
let cachecontrol = cache_control opts
r' | null cachecontrol = r
| otherwise = r{requestHeaders=(hCacheControl, B8.pack cachecontrol):requestHeaders r}
rsp <- httpLbs r' manager
return $ LB8.unpack $ responseBody rsp -- $$+- return () ? https://github.com/snoyberg/http-conduit/issues/97#issuecomment-12876868
Nothing -> opterror $ "could not parse URI: " ++ s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment