http-client-brread-timeout 0.2.0.0 → 0.3.0.0
raw patch · 4 files changed
+57/−19 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Network.HTTP.Client.BrReadWithTimeout: brConsumeWithTimeout :: Int -> Request -> BodyReader -> IO [ByteString]
+ Network.HTTP.Client.BrReadWithTimeout: brConsumeWithTimeout :: Int -> BodyReader -> IO [ByteString]
- Network.HTTP.Client.BrReadWithTimeout: brReadSomeWithTimeout :: Int -> Request -> BodyReader -> Int -> IO ByteString
+ Network.HTTP.Client.BrReadWithTimeout: brReadSomeWithTimeout :: Int -> BodyReader -> Int -> IO ByteString
- Network.HTTP.Client.BrReadWithTimeout: brReadWithTimeout :: Int -> Request -> BodyReader -> IO ByteString
+ Network.HTTP.Client.BrReadWithTimeout: brReadWithTimeout :: Int -> BodyReader -> IO ByteString
Files
- Changelog.md +8/−0
- Network/HTTP/Client/BrReadWithTimeout.hs +45/−17
- README.md +3/−1
- http-client-brread-timeout.cabal +1/−1
Changelog.md view
@@ -1,3 +1,11 @@+### 0.3.0.0++- Functions *brReaWithTimeout*, *brReadSomeWithTimeout*, and+ *brConsumeWithTimeout* now throw clean *ResponseTimeout* without wrapping in+ the request data.+ + **Breaking changes**: functions *brReaWithTimeout*, *brReadSomeWithTimeout*,+ and *brConsumeWithTimeout* no longer accept *Request* parameter.+ ### 0.2.0.0 - Added functions *brReadSomeWithTimeout* and *brConsumeWithTimeout*.
Network/HTTP/Client/BrReadWithTimeout.hs view
@@ -28,7 +28,12 @@ import Network.HTTP.Client import qualified Network.HTTP.Client.Internal- as I (ResponseTimeout (..), mResponseTimeout)+ as I (ResponseTimeout (..)+ ,mResponseTimeout+ ,throwHttp+ ,toHttpException+ ,unHttpExceptionContentWrapper+ ) import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as L import Control.Exception@@ -39,7 +44,10 @@ -- This function returns the value of the timeout on reading response headers -- which can be used to apply equal timeouts between body read events in -- `brReadWithTimeout`, `brReadSomeWithTimeout`, and `brConsumeWithTimeout`.-fromResponseTimeout :: Request -> Manager -> Int+fromResponseTimeout+ :: Request -- ^ Request+ -> Manager -- ^ Manager+ -> Int fromResponseTimeout req man = case responseTimeout req of I.ResponseTimeoutDefault ->@@ -61,13 +69,12 @@ -- -- Throws v'ResponseTimeout' if reading of the next chunk of the response body -- timed out.-brReadWithTimeout :: Int -> Request -> BodyReader -> IO ByteString-brReadWithTimeout tmo req br = timeout tmo br- >>= maybe (throwIO $- HttpExceptionRequest- req { responseTimeout = I.ResponseTimeoutMicro tmo }- ResponseTimeout- ) return+brReadWithTimeout+ :: Int -- ^ Timeout between body read events in microseconds+ -> BodyReader -- ^ Body reader+ -> IO ByteString+brReadWithTimeout tmo br = timeout tmo br+ >>= maybe (I.throwHttp ResponseTimeout) return -- | This is like 'brReadSome' but with a timeout between body read events. --@@ -79,8 +86,12 @@ -- parameter. -- -- @since 0.2.0.0-brReadSomeWithTimeout :: Int -> Request -> BodyReader -> Int -> IO L.ByteString-brReadSomeWithTimeout tmo req br = brReadSome $ brReadWithTimeout tmo req br+brReadSomeWithTimeout+ :: Int -- ^ Timeout between body read events in microseconds+ -> BodyReader -- ^ Body reader+ -> Int -- ^ How many bytes to read+ -> IO L.ByteString+brReadSomeWithTimeout tmo br = brReadSome $ brReadWithTimeout tmo br -- | This is like 'brConsume' but with a timeout between body read events. --@@ -92,25 +103,42 @@ -- parameter. -- -- @since 0.2.0.0-brConsumeWithTimeout :: Int -> Request -> BodyReader -> IO [ByteString]-brConsumeWithTimeout tmo req br = brConsume $ brReadWithTimeout tmo req br+brConsumeWithTimeout+ :: Int -- ^ Timeout between body read events in microseconds+ -> BodyReader -- ^ Body reader+ -> IO [ByteString]+brConsumeWithTimeout tmo br = brConsume $ brReadWithTimeout tmo br -- | This is like 'httpLbs' but with a timeout between body read events. -- -- The value of the timeout is passed in the first parameter as a number of -- microseconds. A negative value effectively disables the timeout which makes -- the function behave exactly as 'httpLbs'.-httpLbsBrReadWithCustomTimeout :: Int -> Request -> Manager ->- IO (Response L.ByteString)+httpLbsBrReadWithCustomTimeout+ :: Int -- ^ Timeout between body read events in microseconds+ -> Request -- ^ Request+ -> Manager -- ^ Manager+ -> IO (Response L.ByteString) httpLbsBrReadWithCustomTimeout tmo req man = withResponse req man $ \res -> do- bss <- brConsumeWithTimeout tmo req $ responseBody res+ bss <- handle (\e -> throwIO $+ let req' = case I.unHttpExceptionContentWrapper e of+ ResponseTimeout ->+ req { responseTimeout =+ I.ResponseTimeoutMicro tmo+ }+ _ -> req+ in I.toHttpException req' e+ ) $ brConsumeWithTimeout tmo $ responseBody res return res { responseBody = L.fromChunks bss } -- | This is like 'httpLbs' but with a timeout between body read events. -- -- The value of the timeout is retrieved from the t'ResponseTimeout' of the -- request.-httpLbsBrReadWithTimeout :: Request -> Manager -> IO (Response L.ByteString)+httpLbsBrReadWithTimeout+ :: Request -- ^ Request+ -> Manager -- ^ Manager+ -> IO (Response L.ByteString) httpLbsBrReadWithTimeout req man = httpLbsBrReadWithCustomTimeout (fromResponseTimeout req man) req man
README.md view
@@ -95,8 +95,10 @@ } ResponseTimeout +While handling HttpExceptionContentWrapper {unHttpExceptionContentWrapper = ResponseTimeout}+ HasCallStack backtrace:- throwIO, called at ./Network/HTTP/Client/BrReadWithTimeout.hs:64:20 in http-client-brread-timeout-0.1.1.1-inplace:Network.HTTP.Client.BrReadWithTimeout+ throwIO, called at ./Network/HTTP/Client/BrReadWithTimeout.hs:123:26 in http-client-brread-timeout-0.3.0.0-inplace:Network.HTTP.Client.BrReadWithTimeout <b>*N.HTTP.C.BrReadWithTimeout></b> httpLbsBrReadWithTimeout reqSlow man Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Server","nginx/1.28.0"),("Date","Thu, 26 Feb 2026 13:37:49 GMT"),("Content-Type","application/octet-stream"),("Transfer-Encoding","chunked"),("Connection","keep-alive")], responseBody = "1\n2\n3\n4\n", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose, responseOriginalRequest = Request {
http-client-brread-timeout.cabal view
@@ -1,5 +1,5 @@ name: http-client-brread-timeout-version: 0.2.0.0+version: 0.3.0.0 synopsis: Http client with time-limited brRead description: Http client with timeouts applied in between body read events. .