Skip to content

Commit

Permalink
http-client: Avoid a space leak when storing original requests
Browse files Browse the repository at this point in the history
`Network.HTTP.Client.Response.getResponse` stores the original request
inside a `Response`, but attempts to override its request body with an
empty one. This record update was lazy, and a reference to the
original request body would persist, causing a space leak.

Force the response to WHNF, and use bang patterns to force the Request
and ultimately its body to WHNF too.
  • Loading branch information
JackKelly-Bellroy committed Jul 5, 2024
1 parent 6f742e8 commit dee2a38
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
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

## Unreleased

* Fix a space leak when storing original requests inside responses

## 0.7.17

* Add `managerSetMaxHeaderLength` to `Client` to change `ManagerSettings` `MaxHeaderLength`.
Expand Down
2 changes: 1 addition & 1 deletion http-client/Network/HTTP/Client/Response.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ getResponse mhl timeout' req@(Request {..}) mconn cont = do
then makeGzipReader body1
else return body1

return Response
return $! Response
{ responseStatus = s
, responseVersion = version
, responseHeaders = hs
Expand Down
4 changes: 2 additions & 2 deletions http-client/Network/HTTP/Client/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ data Request = Request
-- are honoured.
--
-- Since 0.1.0
, requestBody :: RequestBody
, requestBody :: !RequestBody
-- ^ Request body to be sent to the server.
--
-- Since 0.1.0
Expand Down Expand Up @@ -714,7 +714,7 @@ data Response body = Response
-- be impossible.
--
-- Since 0.1.0
, responseOriginalRequest :: Request
, responseOriginalRequest :: !Request
-- ^ Holds original @Request@ related to this @Response@ (with an empty body).
-- This field is intentionally not exported directly, but made available
-- via @getOriginalRequest@ instead.
Expand Down

0 comments on commit dee2a38

Please sign in to comment.