我正在尝试使用膜作为简单的反向代理。当我尝试重写URI时,它仍然转到代理主机上原始请求的URI。
public class Proxy {
public static void main(String[] args) throws Exception {
ServiceProxyKey key = new ServiceProxyKey(4000);
ServiceProxy sp = new ServiceProxy(key, "localhost", 8081);
sp.getInterceptors().add(new ProxyInterceptor());
HttpRouter router = new HttpRouter();
router.add(sp);
router.init();
}
static class ProxyInterceptor extends AbstractInterceptor {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
System.out.println(exc.getRequestURI());
exc.getRequest().setUri("/fish");
System.out.println(exc.getRequest().getUri());
return Outcome.CONTINUE;
}
}
}
我希望传递到代理主机的路径为/fish
,但是发送到端口8081上的代理服务器的请求是原始请求。