2

I need to validate some user requests, so I'm trying to use LittleProxy. The idea is to make it transparent to users (iptables > littleproxy > origin server).

So I'm using iptables to redirect the flow to LittleProxy (that is listening on 127.0.0.1:3127) as follows:

iptables -t nat -A OUTPUT -p tcp -o eth0 --dport 80 -j DNAT --to 127.0.0.1:3127

If I start it using withTransparent(true), I receive an error 400 Bad Request to URI. This occurs due to RFC 7230 compliance.

final HttpProxyServer server = DefaultHttpProxyServer.bootstrap()
   .withPort(3127).withTransparent(true).start();

So I tried to start it as follows, and change the request URI:

final HttpProxyServer server = DefaultHttpProxyServer.bootstrap()
   .withPort(3127).withTransparent(false)
   .withFiltersSource(new HttpFiltersSourceAdapterExt()).start();

And overrided the method as follows:

@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;
}

But changing the URI causes an endless loop into LittleProxy. Each time adding a new Via header.

I also tried to use .withAllowRequestToOriginServer(true) but with .withTransparent(true) will also cause an endless loop.

Studying DirectRequestTest.java I saw that I could test the headers and check if it already have a "Via", but I don't want to abort the request. I still want LittleProxy to call origin server, retrieve and serve the response to users.

So my question is, how do I implement this scenario with LittleProxy?

Bob Rivers
  • 5,261
  • 6
  • 47
  • 59

1 Answers1

0

I think it's because the iptables rule. Littleproxy makes another request to target port 80. The rules takes it and sens again to littleproxy. You should probably put it on another machine.

Michal
  • 384
  • 3
  • 8