Setting up little proxy to forward to Tomcat / Add headers

954 views
Skip to first unread message

chris....@gmail.com

unread,
Jun 13, 2015, 8:39:05 AM6/13/15
to littl...@googlegroups.com

I want to use little proxy so that it:

  1. Listens on port 80

  2. Forwards request to Tomcat on port 8080.

  3. Allows me to add header fields before forwarding to port 8080.

I have not been able to find any examples online that do this sort of thing. Can someone point me to some code/examples that would do this/ Thanks

Frank Ganske

unread,
Jun 15, 2015, 4:15:34 PM6/15/15
to littl...@googlegroups.com
Hi Chris,

this is a very common use case for LittleProxy. Trust me and start with
https://github.com/ganskef/LittleProxy/blob/master/README.md. Consider
to clone the current SNAPSHOT version.

With org.littleshoot.proxy.HttpProxyServerBootstrap:

For 1. use 80 instead of 8080 in withPort(int)

For 2. use withChainProxyManager() with:

ChainedProxyManager chainProxyManager = new ChainedProxyManager() {
public void lookupChainedProxies(HttpRequest httpRequest,
Queue<ChainedProxy> chainedProxies) {
chainedProxies.add(new ChainedProxyAdapter() {
@Override
public InetSocketAddress getChainedProxyAddress() {
return new InetSocketAddress("localhost", 8080);
}
});

chainedProxies.add(ChainedProxyAdapter.FALLBACK_TO_DIRECT_CONNECTION);
}
};

For 3. in your Filter (extends HttpFiltersAdapter) for example:

@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
if (httpObject instanceof HttpRequest) {
HttpRequest request = (HttpRequest) httpObject;
HttpHeaders headers = request.headers();
headers.remove(HttpHeaders.Names.IF_MODIFIED_SINCE);
headers.remove(HttpHeaders.Names.IF_NONE_MATCH);
}
return null;
}


It's only the beginning... Have fun. But, pay attention on Java Non
Blocking IO and the derived concepts in Netty. This is important, I think.


Regards Frank


Am 13.06.2015 um 13:30 schrieb chris....@gmail.com:
>
> I want to use little proxy so that it:
>
> 1.
>
> Listens on port 80
>
> 2.
>
> Forwards request to Tomcat on port 8080.
>
> 3.
>
> Allows me to add header fields before forwarding to port 8080.
>
> I have not been able to find any examples online that do this sort of
> thing. Can someone point me to some code/examples that would do this/ Thanks
>
> --
> You received this message because you are subscribed to the Google
> Groups "LittleProxy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to littleproxy...@googlegroups.com
> <mailto:littleproxy...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

jesus valenzuela

unread,
Jun 28, 2016, 12:26:41 AM6/28/16
to LittleProxy
Hello Frank,

I have been trying to use this example and i cant get it to work the way you describe in this post.

I have set up an apache http server on my local machine. I set up an http client that pushes requests to the server (these requests have strings that i push from my terminal). When i set up LittleProxy using the HttpFiltersAdapter, it only calls the 'clientToProxyRequest' once with a "CONNECT" request. I figured it would call every time the Http Client sends a request to the Server.

What i am trying to do is, capture every request sent from the Client and modify the Headers.

Am i missing something that isn't allowing me to capture every request coming from the Http Client?

Thanks, 
Jesus

Frank Ganske

unread,
Jun 28, 2016, 1:51:50 AM6/28/16
to littl...@googlegroups.com
Hello Jesus,

usually a CONNECT means, you're getting a HTTPS URL, is it? This case you need to intercept the connection. Have a look at LittleProxy-mitm.

In case you get a HTTP URL please tell me what your client is. Proxy tunneling after CONNECT is supported for HTTPS only at the moment. I'll try to reproduce it.

Regards Frank

jesus valenzuela

unread,
Jun 28, 2016, 3:07:15 AM6/28/16
to LittleProxy
Hello Frank, 

I will look at LittleProxy-mitm first thing tomorrow morning.

I am able to tunnel HTTPS connections through the proxy, I just can't view the requests using the HttpFilterAdapter. 

Are you saying that Little Proxy can't tunnel HTTP connections?

Thanks for your quick reply,
Jesus


jesus valenzuela

unread,
Jun 28, 2016, 12:47:38 PM6/28/16
to LittleProxy
Hello Frank, 

I just verified, i tried sending messages through HTTP and i was able to see all requests. I can now modify to sent to server. (I think you mean to say that it only supports HTTP connections at the moment, in your previous message)

Is there a way i can view the HTTPS requests? What are your suggestions to try and see the HTTPS Request. 

I want any client to be able to add headers to any request that comes through the proxy, not just HTTP requests.

Thank, 
Jesus

Frank Ganske

unread,
Jun 28, 2016, 3:20:28 PM6/28/16
to littl...@googlegroups.com, jesus valenzuela
Hi Jesus,

to encrypt the connection to hide the URL, the headers, and all the contents is the purpose of HTTPS. :-) !

Using Man-In-The-Middle breaks this which is normally a bad thing. You are able to it with LittleProxy-mitm or browsermob-proxy MITM with LittleProxy too.

You have to prepare your client to trust your Certificate Authority of course. An application example is ganskef/MoCuishle on GitHub. It's Java integrated with a Mozilla add-on.

Regards Frank

jesus valenzuela

unread,
Jun 28, 2016, 8:30:39 PM6/28/16
to LittleProxy, chu...@gmail.com
Perfect! I got it working with LittleProxy-mitm.

Thanks for your help!
Jesus
Reply all
Reply to author
Forward
0 new messages