vertx-http-proxy icon indicating copy to clipboard operation
vertx-http-proxy copied to clipboard

`originRequestProvider` should be able to access `ProxyContext` to perform routing based on modified request

Open ThorodanBrom opened this issue 3 years ago • 2 comments

Version

Since originRequestProvider runs after pre-request interceptors, there is no way to pass the ProxyContext to perform routing on the based on the modified request. originRequestProvider only has context of the original request in HttpServerRequest

Context

It would be useful if originRequestProvider could perform routing based on what is present in ProxyContext and ProxyRequest. This may also solve #35 - variables can be set in the ProxyContext to perform routing.

The drawback here would be that originRequestProvider must come in between pre-request and post-request interceptors.

ThorodanBrom avatar Jan 27 '23 14:01 ThorodanBrom

One way to solve this would be if we could mention which version of the request should be passed here, the proxied request or the modifies request, when resolving the origin:

https://github.com/eclipse-vertx/vertx-http-proxy/blob/102a33a54ed5b6a1d839f08a64d2305834b581fb/src/main/java/io/vertx/httpproxy/impl/ReverseProxy.java#L216

ThorodanBrom avatar Jan 27 '23 15:01 ThorodanBrom

I had the same need: sharing information between interceptors and originSelector function to perform needed routing.

One option that could be interesting is that originSelector accepts Function<ProxyContext, Future<SocketAddress>> selector). It is possible to get the original request via context.request().proxiedRequest(). This way it is possible to pass information using ProxyConext get/set methods

As a workaround it is possible to use request headers map of the proxiedRequests to pass Strings between interceptors and originSelector (But it is far from clean solution).

The other option is obviously to write the proxy handler and not using interceptors/originin selectors and do everything in the handler. Probably this was not the original idea of the API

chevaris avatar Dec 13 '23 19:12 chevaris