Skip to content

WithRawRequestBodyProvider method signature plays poorly with retries #708

@jamesross3

Description

@jamesross3

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions