GithubHelp home page GithubHelp logo

Comments (4)

jasdel avatar jasdel commented on August 11, 2024

Thanks for reaching out with this issue @moriyoshi. The smithyhttp.Request's Clone intentional did not accept a context via its clone method. The intention behind this was that the Request's Build method was the entity that attached the context to the underlying http.Request and returned a constructed http.Request. Prior to Build being called the http.Request would not have a Context associated with it. Build is intended to be the last action performed on the request before it is used with the HTTP Client.

Could you go into more detail and background about the use case for Clone to take a context?

from smithy-go.

moriyoshi avatar moriyoshi commented on August 11, 2024

So what is the use of Clone() in the first place? Is it supposed to be used only in a middleware? I guess not, because it's used in RequestCloner, whose comment says it's intended to use in a retrier. Then should the retrier be able to feed a fresh context on a retry? I would say yes.

from smithy-go.

jasdel avatar jasdel commented on August 11, 2024

Thanks for the update. The intention of the middleware is that a context is only associated with an individual request at the last possible moment. Basically right before the request is passed to the HTTP client's Do method. This is the reason for Build taking the context but not Clone. Clone is intended to create a copy of the smithyhttp.Request, and that request has no reference to the Context used by the middleware.

The retryer is a component of the middleware which will create a clone of the request to ensure the request body stream is reset correctly. Also to ensure that any mutations by the signer do not leak between request attempts. It doesn't need to provide a context because the request is context-less until Build is called when the request is sent to the HTTP client.

The middleware stack it self passes down a context between each layer, and those middleware can mutate the context as needed. Attaching any middleware specific context to the request could cause that context to be invalid by the time the http client's Do method is called. Or each middleware would need to update the request's context. This would create a clone of the request which is not preferred.

from smithy-go.

jasdel avatar jasdel commented on August 11, 2024

Thanks for reaching out @moriyoshi. I'm going to close this issue. Please reach out and let us know if you have additional questions, feedback, issues, or feature request.

from smithy-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.