You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, WithRawRequestBodyProvider accepts a func() io.ReadCloser. Since instantiating a non-trivial io.ReadCloser depends on various methods which return errors (think os.Open() or, if streaming from some other server, http.Get() -> resp.Body), the WithRawRequestBodyProvider method signature forces an unpleasant decision on users:
construct one ReadCloser and reuse it subsequent requests -> virtually always wrong but a common pattern users follow without recognizing the implications
reconstruct the ReadCloser each call to the func() io.ReadCloser - I'm actually unsure if WithRawRequestBodyProvider would invoke this method multiple times (once per request attempt across some number of request retries), and even if it did, the reconstruction would often need to swallow an error (think f, _ := os.Open("file"); return f)
set the request retries to 1 so the func() io.ReadCloser is only called once (given the prevalence of conjure-go-generated clients, this is often not an option without setting retries to 1 across all usages of the instantiated client)
doing something hairy like providing a RoundTripper that modifies the request body. Given CGR has some opinion about middleware ordering, I don't know if this would even work.
Proposal
Expose methods in CGR that allow users to (1) not have to swallow errors when providing request bodies and (2) state whether the provided request body is reusable or not. A change that fits this proposal is #695
The text was updated successfully, but these errors were encountered:
Currently,
WithRawRequestBodyProvider
accepts afunc() io.ReadCloser
. Since instantiating a non-trivialio.ReadCloser
depends on various methods which return errors (thinkos.Open()
or, if streaming from some other server,http.Get()
->resp.Body
), theWithRawRequestBodyProvider
method signature forces an unpleasant decision on users:func() io.ReadCloser
- I'm actually unsure if WithRawRequestBodyProvider would invoke this method multiple times (once per request attempt across some number of request retries), and even if it did, the reconstruction would often need to swallow an error (thinkf, _ := os.Open("file"); return f
)func() io.ReadCloser
is only called once (given the prevalence of conjure-go-generated clients, this is often not an option without setting retries to 1 across all usages of the instantiated client)Proposal
Expose methods in CGR that allow users to (1) not have to swallow errors when providing request bodies and (2) state whether the provided request body is reusable or not. A change that fits this proposal is #695
The text was updated successfully, but these errors were encountered: