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
Copy the headers from REST requests to the corresponding TransportRequest(s) #6513
Conversation
* but makes sure that the REST headers are copied over from {@link org.elasticsearch.rest.RestRequest} to the | ||
* corresponding {@link org.elasticsearch.action.ActionRequest}(s) | ||
*/ | ||
public class HeadersCopyClient extends AbstractClient { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one should be an inner class in BaseRestHandler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should probably be a common client for all client types... and then it'll just work with whatever client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even after #6517 this is not so easy to achieve keeping type-safety at the same time, because the Client
generic type which can either be Client
, ClusterAdminClient
or IndicesAdminClient
. I'm opting for duplicating the execute methods, it's still less LOC than trying to generalize this so that we have a single pair of execute
methods.
…equests to the corresponding TransportRequest(s) Introduced the use of a FilterClient in all of the REST actions, which delegates all of the operations to the internal Client, but makes sure that the headers are properly copied from REST requests to TransportRequest(s) when it comes to executing them. Closes elastic#6513
I updated the PR after #6517 was committed, ready for review again... |
} | ||
|
||
@Override | ||
public IndicesAdminClient indices() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep the refs to these internal clients
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, just pushed a new commit that addresses this
I think this looks awesome. I am hesitating with the BW break here, IMO it would be nicer to deprecate the |
does it make sense when we copy over the headers, to not copy over common known HTTP headers that are not really used, like Content-Type, Content-Length, ... |
@s1monw I think it's actually better to pass in the @kimchy yea, it makes sense +1 |
fair enough... LGTM |
Pushed a new commit containing a static list of REST headers that need to be copied over to the transport. |
*/ | ||
public abstract class BaseRestHandler extends AbstractComponent implements RestHandler { | ||
|
||
protected final Client client; | ||
private static final Set<String> usefulHeaders = new HashSet<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably be an array
updated tests too to have useful headers that are not part of the rest request
…c addUsefulHeader works (from multiple threads as well)
Pushed a couple of new commits that address @uboness feedback, it should be close. |
LGTM |
…s to the corresponding TransportRequest(s) Introduced the use of the FilterClient in all of the REST actions, which delegates all of the operations to the internal Client, but makes sure that the headers are properly copied if needed from REST requests to TransportRequest(s) when it comes to executing them. Added new abstract handleRequest method to BaseRestHandler with additional Client argument and made private the client instance member (was protected before) to force the use of the client received as argument. The list of headers to be copied over is by default empty but can be extended via plugins. Closes #6513
As a side note, this change is breaking for plugins that add their own REST handlers by extending |
…nsport requests The useful headers are now stored into a `Set` instead of an array so we can easily deduplicate them. A set is also returned instead of an array by the `usefulHeaders` static getter. Relates to elastic#6513 Closes elastic#7590
The functionality of copying headers in the REST layer (from REST requests to transport requests) remains the same. Made it a bit nicer by introducing a ClientFactory component that is a singleton and allows to register useful headers without requiring static methods. Plugins just have to inject the ClientFactory now, and call its `addUsefulHeaders` method that is not static anymore. Relates to elastic#6513 Closes elastic#7594
The functionality of copying headers in the REST layer (from REST requests to transport requests) remains the same. Made it a bit nicer by introducing a RestClientFactory component that is a singleton and allows to register useful headers without requiring static methods. Plugins just have to inject the RestClientFactory now, and call its `addRelevantHeaders` method that is not static anymore. Relates to #6513 Closes #7594
The functionality of copying headers in the REST layer (from REST requests to transport requests) remains the same. Made it a bit nicer by introducing a RestClientFactory component that is a singleton and allows to register useful headers without requiring static methods. Plugins just have to inject the RestClientFactory now, and call its `addRelevantHeaders` method that is not static anymore. Relates to #6513 Closes #7594
Introduced the use of the
FilterClient
in all of the REST actions, which delegates all of the operations to the internalClient
, but makes sure that the headers are properly copied if needed from REST requests toTransportRequest
(s) when it comes to executing them. Added new abstract handleRequest method toBaseRestHandler
with additionalClient
argument and made private the client instance member (was protected before) to force the use of the client received as argument. The list of headers to be copied over is by default empty but can be extended via plugins.Replaces #6464 as it provides a better and safer way to copy headers from REST layer to transport layer.