module Network.Browser.Simple (download) where
import Network.URI
import Network.HTTP
import Network.Browser
import Network.HTTP.Encoding
import Data.ByteString.Lazy
download :: URI -> [Cookie] -> IO (String, [Cookie])
download uri cookies =
browse $ do setAllowRedirects True
setUserAgent "Mozilla/5.0 (compatible; jespresso/1.0)"
setCookies cookies
(_, rsp) <- request (defaultGETRequest_ uri :: Request ByteString)
cks <- getCookies
return (rsp, cks)
>>= \(rsp, cks) -> case decodeBody rsp of
Left msg -> fail $ show msg
Right res -> return (decodedBody res, cks)