reactor-netty icon indicating copy to clipboard operation
reactor-netty copied to clipboard

HttpClient proxy configuration per request

Open jordillachmrf opened this issue 1 year ago • 9 comments

As explained here https://stackoverflow.com/questions/74893474/is-there-any-way-to-imlement-a-rotating-proxy-based-httpclient-in-reactor-netty it would be nice if reactor-netty HttpClient could be configured in a per request basis, instead of being "statically" configured as explained in the docs https://projectreactor.io/docs/netty/1.1.5/reference/index.html#_proxy_support_2

Motivation

Some of our clients are GDRP constrained and based on the location of their servers and our servers(eeuu vs eu) we get 451 status codes(legal reasons)

Desired solution

HttpClient client = HttpClient.create() .proxy((spec, req) -> spec.type(ProxyProvider.Proxy.HTTP) .host("proxy") .port(8080) .nonProxyHosts("localhost") .connectTimeoutMillis(20_000)); req -> HttpClientRequest, if HttpClientRequest would be available then we could route the request to our eeuu proxy or eu proxy based on the destination uri.

Considered alternatives

Have various HttpClients's, handle 451 in our code and fallback to the appropriate HttpClient at runtime

jordillachmrf avatar Mar 27 '23 14:03 jordillachmrf

I will take a look at this issue soon.

pderop avatar Mar 28 '23 09:03 pderop

@jordillachmrf Can you elaborate more about the desired solution? You know the destination URI as this is something the the one that uses the HttpClient provides. Based on this you can then choose which HttpClient to use i.e. the one configured with proxy for x or the one configured with proxy for y.

violetagg avatar Apr 28 '23 05:04 violetagg

And that's exactly how we are tackling this, but keeping the routing solution close the proxy configuration seems to us more appropriate than moving this logic one layer above. We have various "services" that use these various proxied webClients, we have had to wrap these into an artificial layer to hide this complexity. We were wondering that adding this flexibility when configuring the proxy would allow us to get rid of this

jordillachmrf avatar May 01 '23 17:05 jordillachmrf

@jordillachmrf I'm gonna add this to the general backlog. For the time being please use the described solution in my previous comment. The team will discuss when and how this can be implemented. If you can work on this feature and provide a PR, this will be great.

violetagg avatar May 01 '23 17:05 violetagg

@violetagg Is somebody working on this problem?

longkunbetter avatar Aug 28 '23 05:08 longkunbetter

@longkunbetter We are not working on this one. I marked this with help wanted if somebody wants to work on this.

violetagg avatar Aug 30 '23 06:08 violetagg

Hi @violetagg, What would be the best way to implement this? ReqeustConfig like Apache HTTPClient or some other way? like a proxy() method builder itself

punitdarira avatar Jul 01 '24 04:07 punitdarira

@punitdarira Do you want to provide a PR? If yes - some rough idea is to plug the implementation in reactor.netty.http.client.HttpClientConnect.MonoHttpConnect#subscribe, in addition to something like what we have for headers (reactor.netty.http.client.HttpClient#headersWhen). I haven't tried that!

violetagg avatar Jul 01 '24 08:07 violetagg

If you would like to have a proxy per request then what should be the destination URL used for selecting proxy settings?

  • the full URL i.e. http://host:port/path/...
  • or just /path/...

violetagg avatar Jul 10 '24 12:07 violetagg