我需要验证一些用户请求,所以我试图使用LittleProxy。这个想法是让它对用户透明(iptables> littleproxy>原始服务器)。Littleproxy无限循环
所以我使用iptables重定向流量LittleProxy(即监听127.0.0.1:3127)如下:
iptables -t nat -A OUTPUT -p tcp -o eth0 --dport 80 -j DNAT --to 127.0.0.1:3127
如果我启动它使用withTransparent(true)
,我收到一个错误400对URI的错误请求。这是由于遵循RFC 7230而发生的。
final HttpProxyServer server = DefaultHttpProxyServer.bootstrap()
.withPort(3127).withTransparent(true).start();
于是,我就按以下方式启动它,并更改请求URI:
final HttpProxyServer server = DefaultHttpProxyServer.bootstrap()
.withPort(3127).withTransparent(false)
.withFiltersSource(new HttpFiltersSourceAdapterExt()).start();
而且overrided方法如下:
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
if (httpObject instanceof DefaultHttpRequest) {
final DefaultHttpRequest request = (DefaultHttpRequest) httpObject;
final String host = request.headers().get(HttpHeaders.Names.HOST);
request.setUri("http://" + host + request.getUri());
}
return null;
}
但改变URI导致无限循环到LittleProxy中。每次添加新的通过标题。
我也试过用.withAllowRequestToOriginServer(true)
但是.withTransparent(true)
也会造成无限循环。
学习DirectRequestTest.java
我看到我可以测试标题并检查它是否已经有“Via”,但我不想中止请求。我仍然希望LittleProxy调用原始服务器,检索并向用户提供响应。
所以我的问题是,我怎么用LittleProxy实现这个场景?
你想出这一个呢还是Bob? –
我认为你的问题类似于这个问题:https://github.com/adamfisk/LittleProxy/issues/146 –
你可以得到这个工作? –