Undertow: How to control choosing host depends on request body content?

元气小坏坏 提交于 2019-12-11 15:49:27

问题


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:


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)



来源:https://stackoverflow.com/questions/52611607/undertow-how-to-control-choosing-host-depends-on-request-body-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!