http-enumerator 0.6.0.2 → 0.6.2
raw patch · 2 files changed
+44/−15 lines, 2 filesdep ~tlsdep ~tls-extra
Dependency ranges changed: tls, tls-extra
Files
- Network/HTTP/Enumerator.hs +41/−12
- http-enumerator.cabal +3/−3
Network/HTTP/Enumerator.hs view
@@ -68,6 +68,7 @@ , withManager -- * Utility functions , parseUrl+ , semiParseUrl , lbsIter -- * Request bodies , urlEncodedBody@@ -343,20 +344,30 @@ -- Since this function uses 'Failure', the return monad can be anything that is -- an instance of 'Failure', such as 'IO' or 'Maybe'. parseUrl :: Failure HttpException m => String -> m (Request m')-parseUrl s@('h':'t':'t':'p':':':'/':'/':rest) = parseUrl1 s False rest-parseUrl s@('h':'t':'t':'p':'s':':':'/':'/':rest) = parseUrl1 s True rest-parseUrl x = failure $ InvalidUrlException x "Invalid scheme"+parseUrl = parseUrlHelper True +-- | Same as 'parseUrl', with one distinction: this function will not attempt+-- to parse the query string, but instead leave it with the path info. This can+-- be useful if you need precise control of the rendering of the query string,+-- such as using semicolons instead of ampersands.+semiParseUrl :: Failure HttpException m => String -> m (Request m')+semiParseUrl = parseUrlHelper False++parseUrlHelper :: Failure HttpException m => Bool -> String -> m (Request m')+parseUrlHelper parsePath s@('h':'t':'t':'p':':':'/':'/':rest) = parseUrl1 s False parsePath rest+parseUrlHelper parsePath s@('h':'t':'t':'p':'s':':':'/':'/':rest) = parseUrl1 s True parsePath rest+parseUrlHelper _ x = failure $ InvalidUrlException x "Invalid scheme"+ parseUrl1 :: Failure HttpException m- => String -> Bool -> String -> m (Request m')-parseUrl1 full sec s =- parseUrl2 full sec s'+ => String -> Bool -> Bool -> String -> m (Request m')+parseUrl1 full sec parsePath s =+ parseUrl2 full sec parsePath s' where s' = encodeString s parseUrl2 :: Failure HttpException m- => String -> Bool -> String -> m (Request m')-parseUrl2 full sec s = do+ => String -> Bool -> Bool -> String -> m (Request m')+parseUrl2 full sec parsePath s = do port' <- mport return Request { host = S8.pack hostname@@ -368,10 +379,12 @@ else return False , requestHeaders = [] , path = S8.pack- $ if null path'+ $ if null path'' then "/"- else concatMap encodeUrlCharPI path'- , queryString = W.parseQuery $ S8.pack qstring+ else concatMap encodeUrlCharPI path''+ , queryString = if parsePath+ then W.parseQuery $ S8.pack qstring+ else [] , requestBody = RequestBodyLBS L.empty , method = "GET" }@@ -379,6 +392,7 @@ (beforeSlash, afterSlash) = break (== '/') s (hostname, portStr) = break (== ':') beforeSlash (path', qstring') = break (== '?') afterSlash+ path'' = if parsePath then path' else afterSlash qstring'' = case qstring' of '?':x -> x _ -> qstring'@@ -416,6 +430,11 @@ -- -- Please see 'lbsIter' for more information on how the 'Response' value is -- created.+--+-- Even though a 'Response' contains a lazy bytestring, this function does+-- /not/ utilize lazy I/O, and therefore the entire response body will live in+-- memory. If you want constant memory usage, you'll need to write your own+-- iteratee and use 'http' or 'httpRedirect' directly. httpLbs :: MonadIO m => Request m -> Manager -> m Response httpLbs req = run_ . http req lbsIter @@ -425,9 +444,14 @@ -- This function will 'failure' an 'HttpException' for any response with a -- non-2xx status code. It uses 'parseUrl' to parse the input. This function -- essentially wraps 'httpLbsRedirect'.+--+-- Note: Even though this function returns a lazy bytestring, it does /not/+-- utilize lazy I/O, and therefore the entire response body will live in+-- memory. If you want constant memory usage, you'll need to write your own+-- iteratee and use 'http' or 'httpRedirect' directly. simpleHttp :: (MonadIO m, Failure HttpException m) => String -> m L.ByteString simpleHttp url = do- url' <- parseUrl url+ url' <- parseUrlHelper False url Response sc _ b <- liftIO $ withManager $ httpLbsRedirect url' if 200 <= sc && sc < 300 then return b@@ -507,6 +531,11 @@ -- -- Please see 'lbsIter' for more information on how the 'Response' value is -- created.+--+-- Even though a 'Response' contains a lazy bytestring, this function does+-- /not/ utilize lazy I/O, and therefore the entire response body will live in+-- memory. If you want constant memory usage, you'll need to write your own+-- iteratee and use 'http' or 'httpRedirect' directly. httpLbsRedirect :: (MonadIO m, Failure HttpException m) => Request m -> Manager -> m Response httpLbsRedirect req = run_ . httpRedirect req lbsIter
http-enumerator.cabal view
@@ -1,5 +1,5 @@ name: http-enumerator-version: 0.6.0.2+version: 0.6.2 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -32,8 +32,8 @@ , zlib-enum >= 0.2 && < 0.3 , http-types >= 0.6 && < 0.7 , blaze-builder-enumerator >= 0.2 && < 0.3- , tls >= 0.5.1 && < 0.6- , tls-extra >= 0.1.6 && < 0.2+ , tls >= 0.6 && < 0.7+ , tls-extra >= 0.2 && < 0.3 , monad-control >= 0.2 && < 0.3 , containers >= 0.2 && < 0.5 , certificate >= 0.7 && < 0.8