http-client-brread-timeout 0.1.0.2 → 0.1.1.0
raw patch · 4 files changed
+40/−35 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Network.HTTP.Client.BrReadWithTimeout: httpLbsBrReadWithCustomTimeout :: Int -> Request -> Manager -> IO (Response ByteString)
Files
- Changelog.md +4/−0
- Network/HTTP/Client/BrReadWithTimeout.hs +14/−4
- README.md +21/−30
- http-client-brread-timeout.cabal +1/−1
Changelog.md view
@@ -1,3 +1,7 @@+### 0.1.1.0++- Added function *httpLbsBrReadWithCustomTimeout*.+ ### 0.1.0.0 - Initial version.
Network/HTTP/Client/BrReadWithTimeout.hs view
@@ -21,6 +21,7 @@ module Network.HTTP.Client.BrReadWithTimeout ( fromResponseTimeout ,brReadWithTimeout+ ,httpLbsBrReadWithCustomTimeout ,httpLbsBrReadWithTimeout ) where @@ -68,11 +69,20 @@ -- | 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 tmo req man = withResponse req man $ \res -> do+ bss <- brConsume $ brReadWithTimeout tmo req $ 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 'ResponseTimeout' of the -- request. httpLbsBrReadWithTimeout :: Request -> Manager -> IO (Response L.ByteString)-httpLbsBrReadWithTimeout req man = withResponse req man $ \res -> do- let tmo = fromResponseTimeout req man- bss <- brConsume $ brReadWithTimeout tmo req $ responseBody res- return res { responseBody = L.fromChunks bss }+httpLbsBrReadWithTimeout req man =+ httpLbsBrReadWithCustomTimeout (fromResponseTimeout req man) req man
README.md view
@@ -32,29 +32,19 @@ server_name main; location /slow {- # send a single response body chunk once in 20 sec- echo 1;- echo_flush;- echo_sleep 20;- echo 2;- echo_flush;- echo_sleep 20;- echo 3;- echo_flush;- echo_sleep 20;+ echo 1; echo_flush;+ # send extra chunks of the response body once in 20 sec+ echo_sleep 20; echo 2; echo_flush;+ echo_sleep 20; echo 3; echo_flush;+ echo_sleep 20; echo 4; } location /very/slow {- echo 1;- echo_flush;- echo_sleep 20;- # chunk 2 is extremely slow (40 sec)- echo 2;- echo_flush;- echo_sleep 40;- echo 3;- echo_flush;- echo_sleep 20;+ echo 1; echo_flush;+ echo_sleep 20; echo 2; echo_flush;+ # chunk 3 is extremely slow (40 sec)+ echo_sleep 40; echo 3; echo_flush;+ echo_sleep 20; echo 4; } } }@@ -71,7 +61,7 @@ <b>Prelude HTTP.Client BrReadWithTimeout></b> reqSlow <- parseRequest "GET http://127.0.0.1:8010/slow" <b>Prelude HTTP.Client BrReadWithTimeout></b> :set +s <b>Prelude HTTP.Client BrReadWithTimeout></b> httpLbs reqVerySlow man-Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Server","nginx/1.22.0"),("Date","Wed, 22 Jun 2022 03:54:43 GMT"),("Content-Type","application/octet-stream"),("Transfer-Encoding","chunked"),("Connection","keep-alive")], responseBody = "1\n2\n3\n", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose, responseOriginalRequest = Request {+Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Server","nginx/1.22.0"),("Date","Thu, 23 Jun 2022 22:04:02 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 { host = "127.0.0.1" port = 8010 secure = False@@ -87,7 +77,7 @@ proxySecureMode = ProxySecureWithConnect } }-(80.11 secs, 1,087,472 bytes)+(80.09 secs, 1,084,840 bytes) <b>Prelude HTTP.Client BrReadWithTimeout></b> httpLbsBrReadWithTimeout reqVerySlow man *** Exception: HttpExceptionRequest Request { host = "127.0.0.1"@@ -106,7 +96,7 @@ } ResponseTimeout <b>Prelude HTTP.Client BrReadWithTimeout></b> httpLbsBrReadWithTimeout reqSlow man-Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Server","nginx/1.22.0"),("Date","Wed, 22 Jun 2022 03:57:20 GMT"),("Content-Type","application/octet-stream"),("Transfer-Encoding","chunked"),("Connection","keep-alive")], responseBody = "1\n2\n3\n", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose, responseOriginalRequest = Request {+Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Server","nginx/1.22.0"),("Date","Thu, 23 Jun 2022 22:08:46 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 { host = "127.0.0.1" port = 8010 secure = False@@ -122,7 +112,7 @@ proxySecureMode = ProxySecureWithConnect } }-(60.07 secs, 1,077,320 bytes)+(60.07 secs, 1,082,880 bytes) </pre> Here, the first request comes from the standard `httpLbs` which, after timely@@ -130,10 +120,11 @@ chunk of the body), no longer applies any timeouts and may last as long as the response endures: in this case, it lasts 80 seconds and successfully returns. In the second request, `httpLbsBrReadWithTimeout` timely receives the first-chunk of the response too, however the second chunk is coming in 40 seconds-which exceeds the default response timeout value (30 seconds), and the function-throws `ResponseTimeout` exception after 50 seconds from the start. In the third-request, `httpLbsBrReadWithTimeout` returns successfully after 60 seconds-because every chunk of the response comes every 20 seconds without triggering-timeouts.+chunk of the response too, the second chunk comes in 20 seconds, and finally,+as the third chunk is going to come in 40 seconds which exceeds the default+response timeout value (30 seconds), the function throws `ResponseTimeout`+exception after 50 seconds from the start of the request. In the third request,+`httpLbsBrReadWithTimeout` returns successfully after 60 seconds because every+extra chunk of the response was coming every 20 seconds without triggering the+timeout.
http-client-brread-timeout.cabal view
@@ -1,5 +1,5 @@ name: http-client-brread-timeout-version: 0.1.0.2+version: 0.1.1.0 synopsis: Http client with time-limited brRead description: Http client with timeouts applied in between body read events. .