-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Ability to construct a detached client Request #7994
Comments
Seems like the |
I'm familiar with setting a request tag in one section of the code and looking it up in a different section, but I don't see how this can help with the above scenario. I assume you mean using different proxies depending on the Request tag, but I'm not sure how to do that. Can you please clarify what you meant, and possibly provide some example code? |
@cowwoc not sure I understand what you're trying to achieve. From your description you don't need to build a request to look it up in the cache, you just use whatever information you already have (which you would put into a If there is a cache hit, you don't build the If there is a cache miss, you pick the proxy, which means you pick the client, and you are good. If the above is correct, then there is no "detach the request" issue. BTW the request is already "detached", in a way. Try this: HttpClient client1 = ...;
HttpClient client2 = ...;
Request request1 = client1.newRequest(...);
HttpDestination destination2 = client2.resolveDestination(origin);
destination2.send(request1, result -> { ... }); The above should allow you to send a request with any client. |
You can use a tag to differentiate between proxies (you need to write your own Proxy subclass though - I did not try but should be doable, something along the lines of The idea is that In pseudo code: HttpClient client = ...;
List<Proxy> proxies = client.getProxyConfiguration().getProxies();
proxies.add(new TaggedHttpProxy("proxyHost1", proxyPort1, "proxyTag1");
proxies.add(new TaggedHttpProxy("proxyHost2", proxyPort2, "proxyTag2");
client.newRequest("serverHost", serverPort)
.tag("proxyTag2")
.send(); The code above should send the request through Let us know if it works for you. |
@sbordet I tried implementing the
So the proxy gets dropped if the server returns any redirect. Shouldn't |
The following workaround worked for me and I can now use a single
I'll wait for you to confirm whether this will get fixed in the main codebase. Thanks! |
@cowwoc I think it's a bug, good catch! |
Implemented copy of the request tag that was mistakenly missing. Signed-off-by: Simone Bordet <[email protected]>
Filed #8103. |
Cool, thank you :) You can close this issue now if you want. |
Target Jetty version(s)
10
Enhancement Description
It would be nice to be able to construct a client-side
Request
independently of anHttpClient
instance.Use-case:
HttpClient
does provide the ability to specify proxies at request-construction time, so I am forced to construct multipleHttpClient
s (one per proxy).Request
independent of a specificHttpClient
, look it up in the cache, and if no match is found bind it to a specificHttpClient
and send out the request.As an aside, Apache's HttpClient allows construction and configuration of unbound Request objects. Requests are bound to clients at the very last minute in order to send them out.
OkHttp
does the same.It would also be great to be able to specify proxies on a per-
Request
basis. This would allow me to use a singleHttpClient
.The text was updated successfully, but these errors were encountered: