Undertow: How to control choosing host depends on

2019-08-28 04:03发布

I try to implement my own proxy like this:

LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient()
        .addHost(new URI("http://localhost:8080"))
        .addHost(new URI("http://localhost:7777"))
        .setConnectionsPerThread(20);

Undertow reverseProxy = Undertow.builder()
        .addHttpListener(8081, "localhost")
        .setIoThreads(1)
        .setHandler(ProxyHandler.builder().setProxyClient(loadBalancer).setMaxRequestTime(30000).build())
        .build();
reverseProxy.start();

I want to have control over choosing proxy server. Depends on request body I want to choose localhost:8080 or localhost:7777

Is it possible in Undertow proxy?

P.S. I am ready to switch to another proxy if it is impossible for undertow

1条回答
Explosion°爆炸
2楼-- · 2019-08-28 05:02

I am using Jetty org.eclipse.jetty.proxy.ProxyServlet managing a dynamic list of backends.

You can select the target backend overriding: org.eclipse.jetty.proxy.AbstractProxyServlet.rewriteTarget(HttpServletRequest)

(I would like to use Undertow only too)

查看更多
登录 后发表回答