@@ -112,6 +112,7 @@ module Network.HTTP.Req
112112 -- $making-a-request
113113 req,
114114 reqBr,
115+ reqCb,
115116 req',
116117 withReqManager,
117118
@@ -429,12 +430,7 @@ req ::
429430 -- | Response
430431 m response
431432req method url body responseProxy options =
432− reqBr method url body (options <> extraOptions) getHttpResponse
433− where
434− extraOptions =
435− case acceptHeader responseProxy of
436− Nothing -> mempty
437− Just accept -> header "Accept" accept
433+ reqCb method url body responseProxy options pure
438434
439435-- | A version of 'req' that does not use one of the predefined instances of
440436-- 'HttpResponse' but instead allows the user to consume @'L.Response'
@@ -459,7 +455,58 @@ reqBr ::
459455 (L.Response L.BodyReader -> IO a) ->
460456 -- | Result
461457 m a
462−reqBr method url body options consume = req' method url body options $ \request manager -> do
458+reqBr method url body options consume =
459+ req' method url body options (reqHandler consume)
460+
461+-- | A version of 'req' that takes a callback to modify the @'L.Request',
462+-- but otherwise performs the request identically.
463+--
464+-- @since 3.7.0
465+reqCb ::
466+ ( MonadHttp m,
467+ HttpMethod method,
468+ HttpBody body,
469+ HttpResponse response,
470+ HttpBodyAllowed (AllowsBody method) (ProvidesBody body)
471+ ) =>
472+ -- | HTTP method
473+ method ->
474+ -- | 'Url'—location of resource
475+ Url scheme ->
476+ -- | Body of the request
477+ body ->
478+ -- | A hint how to interpret response
479+ Proxy response ->
480+ -- | Collection of optional parameters
481+ Option scheme ->
482+ -- | Callback to modify the request
483+ (L.Request -> m L.Request) ->
484+ -- | Response
485+ m response
486+reqCb method url body responseProxy options adjustRequest =
487+ req' method url body (options <> extraOptions) $ \request manager -> do
488+ request' <- adjustRequest request
489+ reqHandler getHttpResponse request' manager
490+ where
491+ extraOptions =
492+ case acceptHeader responseProxy of
493+ Nothing -> mempty
494+ Just accept -> header "Accept" accept
495+
496+-- | The default handler function that the higher-level request functions
497+-- pass to 'req''. Internal function.
498+--
499+-- @since 3.7.0
500+reqHandler ::
501+ MonadHttp m =>
502+ -- | How to get final result from a 'L.Response'
503+ (L.Response L.BodyReader -> IO b) ->
504+ -- | 'L.Request' to perform
505+ L.Request ->
506+ -- | 'L.Manager' to use
507+ L.Manager ->
508+ m b
509+reqHandler consume request manager = do
463510 HttpConfig {..} <- getHttpConfig
464511 let wrapVanilla = handle (throwIO . VanillaHttpException)
465512 wrapExc = handle (throwIO . LI.toHttpException request)