diff --git a/http-client/Network/HTTP/Client.hs b/http-client/Network/HTTP/Client.hs index 9efa501f..996ca300 100644 --- a/http-client/Network/HTTP/Client.hs +++ b/http-client/Network/HTTP/Client.hs @@ -181,7 +181,6 @@ module Network.HTTP.Client , responseHeaders , responseBody , responseCookieJar - , getOriginalRequest , throwErrorStatusCodes -- ** Response body , BodyReader diff --git a/http-client/Network/HTTP/Client/Core.hs b/http-client/Network/HTTP/Client/Core.hs index 45b6b388..5b75ed6a 100644 --- a/http-client/Network/HTTP/Client/Core.hs +++ b/http-client/Network/HTTP/Client/Core.hs @@ -206,7 +206,7 @@ responseOpen inputReq manager' = do wrapExc req0 $ mWrapException manager req0 $ do (req, res) <- go manager (redirectCount req0) req0 checkResponse req req res - mModifyResponse manager res + mModifyResponse manager inputReqNoBody res { responseBody = wrapExc req0 (responseBody res) } where @@ -224,6 +224,8 @@ responseOpen inputReq manager' = do return (res, fromMaybe req'' mreq, isJust mreq)) req' + inputReqNoBody = inputReq { requestBody = "" } + -- | Redirect loop. httpRedirect :: Int -- ^ 'redirectCount' diff --git a/http-client/Network/HTTP/Client/Manager.hs b/http-client/Network/HTTP/Client/Manager.hs index c8bb5518..4b254039 100644 --- a/http-client/Network/HTTP/Client/Manager.hs +++ b/http-client/Network/HTTP/Client/Manager.hs @@ -89,7 +89,7 @@ defaultManagerSettings = ManagerSettings in handle wrapper , managerIdleConnectionCount = 512 , managerModifyRequest = return - , managerModifyResponse = return + , managerModifyResponse = const return , managerProxyInsecure = defaultProxy , managerProxySecure = defaultProxy } diff --git a/http-client/Network/HTTP/Client/Response.hs b/http-client/Network/HTTP/Client/Response.hs index d6f094e2..b85d1192 100644 --- a/http-client/Network/HTTP/Client/Response.hs +++ b/http-client/Network/HTTP/Client/Response.hs @@ -4,7 +4,6 @@ module Network.HTTP.Client.Response ( getRedirectedRequest , getResponse , lbsResponse - , getOriginalRequest ) where import Data.ByteString (ByteString) @@ -124,7 +123,6 @@ getResponse timeout' req@(Request {..}) mconn cont = do , responseBody = body , responseCookieJar = Data.Monoid.mempty , responseClose' = ResponseClose (cleanup False) - , responseOriginalRequest = req {requestBody = ""} } -- | Does this response have no body? @@ -135,11 +133,3 @@ hasNoBody "HEAD" _ = True hasNoBody _ 204 = True hasNoBody _ 304 = True hasNoBody _ i = 100 <= i && i < 200 - --- | Retrieve the orignal 'Request' from a 'Response' --- --- Note that the 'requestBody' is not available and always set to empty. --- --- @since 0.7.8 -getOriginalRequest :: Response a -> Request -getOriginalRequest = responseOriginalRequest diff --git a/http-client/Network/HTTP/Client/Types.hs b/http-client/Network/HTTP/Client/Types.hs index 3b09d6a0..3bebf2fe 100644 --- a/http-client/Network/HTTP/Client/Types.hs +++ b/http-client/Network/HTTP/Client/Types.hs @@ -693,12 +693,6 @@ data Response body = Response -- be impossible. -- -- Since 0.1.0 - , responseOriginalRequest :: Request - -- ^ Holds original @Request@ related to this @Response@ (with an empty body). - -- This field is intentionally not exported directly, but made availble - -- via @getOriginalRequest@ instead. - -- - -- Since 0.7.8 } deriving (Show, T.Typeable, Functor, Data.Foldable.Foldable, Data.Traversable.Traversable) @@ -776,9 +770,12 @@ data ManagerSettings = ManagerSettings -- Default: no modification -- -- Since 0.4.4 - , managerModifyResponse :: Response BodyReader -> IO (Response BodyReader) + , managerModifyResponse :: Request -> Response BodyReader -> IO (Response BodyReader) -- ^ Perform the given modification to a @Response@ after receiving it. -- + -- The Request is the corresponding original request (before any redirects) + -- but its body is always discarded. + -- -- Default: no modification -- -- @since 0.5.5 @@ -818,7 +815,7 @@ data Manager = Manager , mWrapException :: forall a. Request -> IO a -> IO a , mModifyRequest :: Request -> IO Request , mSetProxy :: Request -> Request - , mModifyResponse :: Response BodyReader -> IO (Response BodyReader) + , mModifyResponse :: Request -> Response BodyReader -> IO (Response BodyReader) -- ^ See 'managerProxy' } deriving T.Typeable diff --git a/http-client/test/Network/HTTP/ClientSpec.hs b/http-client/test/Network/HTTP/ClientSpec.hs index d6e25c3a..5561e1da 100644 --- a/http-client/test/Network/HTTP/ClientSpec.hs +++ b/http-client/test/Network/HTTP/ClientSpec.hs @@ -63,8 +63,8 @@ spec = describe "Client" $ do context "managerModifyResponse" $ do it "allows to modify the response status code" $ do - let modify :: Response BodyReader -> IO (Response BodyReader) - modify res = do + let modify :: Request -> Response BodyReader -> IO (Response BodyReader) + modify _req res = do return res { responseStatus = (responseStatus res) { statusCode = 201 @@ -76,8 +76,8 @@ spec = describe "Client" $ do (statusCode.responseStatus) res `shouldBe` 201 it "modifies the response body" $ do - let modify :: Response BodyReader -> IO (Response BodyReader) - modify res = do + let modify :: Request -> Response BodyReader -> IO (Response BodyReader) + modify _req res = do reader <- constBodyReader [BS.pack "modified response body"] return res { responseBody = reader