-
Notifications
You must be signed in to change notification settings - Fork 23
Closed
Description
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 (thinkf, _ := os.Open("file"); return f) - set the request retries to 1 so the
func() io.ReadCloseris 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels