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

Reusable HTTPRequests? #53

Closed
NiteshKant opened this issue Feb 26, 2014 · 2 comments
Closed

Reusable HTTPRequests? #53

NiteshKant opened this issue Feb 26, 2014 · 2 comments

Comments

@NiteshKant
Copy link
Member

HttpRequest provided by HttpClient contains a ContentSource which is a collection of Objects that would be sent as payload of the HTTP request sent by HttpClient.

In order for Ribbon or any other higher level framework to provide retries, it is imperative that it should be able to send the same request to multiple clients. However, with the current model, the same HttpRequest can not be reused as the ContentSource contains state of the iteration.

Assuming we want to support usecases like this, without forcing the users to clone the object before every use, there is the following we have to do:

  • The framework overwrites any state changes it makes to headers while sending the request, eg: The host header.
  • The content source set in the HttpRequest should provide a way to reset state. This can be achieved in two possible ways:
    • Provide a reset method on the ContentSource. This is too intrusive for content sources that do not need reuse and providing a different interface adds to confusion.
    • Return a new instance of ContentSource, every time a request is to be sent i.e. instead of returning the same contentSource object here return a new instance every time. In order to achieve this, we would have to optionally provide a override method of withContentSource() that takes a ContentSourceFactory. In case, this factory is set, we would use this factory to create the new content source instance, else we will use the content source object as is.

@benjchristensen @g9yuayon @allenxwang Thoughts?

allenxwang pushed a commit that referenced this issue Mar 1, 2014
@allenxwang
Copy link

It is not clear what the intention of the withContent_() APIs is when such methods are called multiple times. To me, the with_ methods gives a feeling that the final state of the HttpRequest is the union of those. But it seems that the real intention is that they should override each other. Also, the raw content and content are mutually exclusive. Should we reflect those points in the API design and make the intention clear to the user?

@allenxwang allenxwang reopened this Mar 3, 2014
@NiteshKant
Copy link
Member Author

@allenxwang do you have some suggestions as to how these can be more intutive?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants