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

Unable to update requestBody without using a deprecated record setter #849

Closed
Profpatsch opened this issue Jun 18, 2021 · 8 comments
Closed

Comments

@Profpatsch
Copy link
Contributor

https://hackage.haskell.org/package/wai-3.2.2.1/docs/Network-Wai.html#v:requestBody is deprecated, thus there is no way of using it as a setter without using a deprecated symbol.

I used the following workaround module, I suggest we add this setter function:

{-# OPTIONS_GHC -Wno-deprecations #-}
{-# OPTIONS_GHC -Wno-name-shadowing #-}

module Wai where

import Data.ByteString (ByteString)
import Network.Wai (Request (requestBody))

-- | Workaround to un-deprecate the setter. see 'requestBody'.
setRequestBodyChunk :: IO ByteString -> Request -> Request
setRequestBodyChunk requestBody r =
  r {requestBody = requestBody}
@snoyberg
Copy link
Member

PR welcome

@Vlix
Copy link
Contributor

Vlix commented Oct 13, 2023

Would setRequestBodySource be a more appropriate name?

@kazu-yamamoto
Copy link
Contributor

I guess that @Profpatsch chose setRequestBodyChunk as a partner of getRequestBodyChunk.

@Vlix
Copy link
Contributor

Vlix commented Oct 17, 2023

Yeah, but it's not setting a chunk... so would it maybe be better to then just name it setRequestBody?

It's an easy addition, so I think I might pick this up. (maybe bundle it together with #710 )

EDIT: Just saw @dbeacham made a PR for this. #949

@kazu-yamamoto
Copy link
Contributor

In my understanding, this IO ByteString can be called multiple times and returns "" finally.
I call it chunks.

@Vlix
Copy link
Contributor

Vlix commented Oct 17, 2023

Hmmm, ok I can see your point. I guess the most important thing is to emphatically add documentation that the IO ByteString MUST provide data until the request body is completely produced, after which it MUST return "". So for example that someone shouldn't setRequestBodyChunk (pure bytestring) request, because that will cause loops or memory leaks if someone expects it to produce chunks. 🤔

Should we move this discussion over to #949 or should @dbeacham just keep an eye on this discussion? 😅

@dbeacham
Copy link

In my understanding, this IO ByteString can be called multiple times and returns "" finally.
I call it chunks.

I think setRequestBodyChunks is a reasonable name to complement getRequestBodyChunk given how they are both expected to behave.

I can also add some docs to mirror the information given in requestBody and getRequestBodyChunk that it should return "" once the body has been fully produced.

@Vlix
Copy link
Contributor

Vlix commented Oct 19, 2023

Implemented in #949

@Vlix Vlix closed this as completed Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants