Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add original Request to the Response type. #464

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions http-client/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for http-client

## 0.7.8

* Include the original `Request` in the `Response`. Expose it via `getOriginalRequest`.

## 0.7.7

* Allow secure cookies for localhost without HTTPS [#460](https://github.com/snoyberg/http-client/pull/460)
Expand Down
1 change: 1 addition & 0 deletions http-client/Network/HTTP/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ module Network.HTTP.Client
, responseHeaders
, responseBody
, responseCookieJar
, getOriginalRequest
, throwErrorStatusCodes
-- ** Response body
, BodyReader
Expand Down
10 changes: 10 additions & 0 deletions http-client/Network/HTTP/Client/Response.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Network.HTTP.Client.Response
( getRedirectedRequest
, getResponse
, lbsResponse
, getOriginalRequest
) where

import Data.ByteString (ByteString)
Expand Down Expand Up @@ -123,6 +124,7 @@ 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?
Expand All @@ -133,3 +135,11 @@ 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
6 changes: 6 additions & 0 deletions http-client/Network/HTTP/Client/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,12 @@ 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)

Expand Down
2 changes: 1 addition & 1 deletion http-client/http-client.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: http-client
version: 0.7.7
version: 0.7.8
synopsis: An HTTP client engine
description: Hackage documentation generation is not reliable. For up to date documentation, please see: <http://www.stackage.org/package/http-client>.
homepage: https://github.com/snoyberg/http-client
Expand Down