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

WithRawRequestBodyProvider method signature plays poorly with retries #708

Open
jamesross3 opened this issue Oct 25, 2024 · 0 comments
Open

Comments

@jamesross3
Copy link
Contributor

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

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

1 participant