@@ -112,6 +112,7 @@ module Network.HTTP.Req
112 -- $making-a-request
112 -- $making-a-request
116 withReqManager,
117 withReqManager,
@@ -429,12 +430,7 @@ req ::
429 -- | Response
430 -- | Response
430 m response
431 m response
431req method url body responseProxy options =
432req method url body responseProxy options =
432− reqBr method url body (options <> extraOptions) getHttpResponse
433+ reqCb method url body responseProxy options pure
435− case acceptHeader responseProxy of
437− Just accept -> header "Accept" accept
439-- | A version of 'req' that does not use one of the predefined instances of
435-- | A version of 'req' that does not use one of the predefined instances of
440-- 'HttpResponse' but instead allows the user to consume @'L.Response'
436-- 'HttpResponse' but instead allows the user to consume @'L.Response'
@@ -459,7 +455,58 @@ reqBr ::
459 (L.Response L.BodyReader -> IO a) ->
455 (L.Response L.BodyReader -> IO a) ->
460 -- | Result
456 -- | Result
458+reqBr method url body options consume =
459+ req' method url body options (reqHandler consume)
461+-- | A version of 'req' that takes a callback to modify the @'L.Request',
462+-- but otherwise performs the request identically.
469+ HttpResponse response,
470+ HttpBodyAllowed (AllowsBody method) (ProvidesBody body)
474+ -- | 'Url'—location of resource
476+ -- | Body of the request
478+ -- | A hint how to interpret response
480+ -- | Collection of optional parameters
482+ -- | Callback to modify the request
483+ (L.Request -> m L.Request) ->
486+reqCb method url body responseProxy options adjustRequest =
462−reqBr method url body options consume = req' method url body options $ \request manager -> do
487+ req' method url body (options <> extraOptions) $ \request manager -> do
488+ request' <- adjustRequest request
489+ reqHandler getHttpResponse request' manager
492+ case acceptHeader responseProxy of
494+ Just accept -> header "Accept" accept
496+-- | The default handler function that the higher-level request functions
497+-- pass to 'req''. Internal function.
502+ -- | How to get final result from a 'L.Response'
503+ (L.Response L.BodyReader -> IO b) ->
504+ -- | 'L.Request' to perform
506+ -- | 'L.Manager' to use
509+reqHandler consume request manager = do
463 HttpConfig {..} <- getHttpConfig
510 HttpConfig {..} <- getHttpConfig
464 let wrapVanilla = handle (throwIO . VanillaHttpException)
511 let wrapVanilla = handle (throwIO . VanillaHttpException)
465 wrapExc = handle (throwIO . LI.toHttpException request)
512 wrapExc = handle (throwIO . LI.toHttpException request)