- Notifications
You must be signed in to change notification settings - Fork0
High performance HTTP proxy originally written by your friends at Lantern and now maintained by volunteer open source programmers. This fork of adamfisk's repository was created in order to keep the project alive.
License
amit2103/LittleProxy
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is an updated fork of adamfisk's LittleProxy. The original project appearsto have been abondoned. Because it's so incredibly useful, it's being broughtback to life in this repository.
LittleProxy is a high performance HTTP proxy written in Java atop Trustin Lee'sexcellentNetty event-based networking library. It's quitestable, performs well, and is easy to integrate into your projects.
One option is to clone LittleProxy and run it from the command line. This is as simple as:
$ git clone git@github.com:mrog/LittleProxy.git$ cd LittleProxy$ ./run.bash
You can embed LittleProxy in your own projects through Maven with the following:
<dependency> <groupId>xyz.rogfam</groupId> <artifactId>littleproxy</artifactId> <version>2.0.0-beta-5</version> </dependency>
Or with Gradle like this
compile "xyz.rogfam:littleproxy:2.0.0-beta-5"
Once you've included LittleProxy, you can start the server with the following:
HttpProxyServerserver =DefaultHttpProxyServer.bootstrap() .withPort(8080) .start();
To intercept and manipulate HTTPS traffic, LittleProxy uses a man-in-the-middle (MITM) manager. LittleProxy's defaultimplementation (SelfSignedMitmManager
) has a fairly limited feature set. For greater control over certificate impersonation,browser trust, the TLS handshake, and more, use a the LittleProxy-compatible MITM extension:
- LittleProxy-mitm - A LittleProxy MITM extension that aims to support every Java platform including Android
- mitm - A LittleProxy MITM extension that supports elliptic curve cryptography and custom trust stores
To filter HTTP traffic, you can add request and response filters using aHttpFiltersSource(Adapter)
, for example:
HttpProxyServerserver =DefaultHttpProxyServer.bootstrap() .withPort(8080) .withFiltersSource(newHttpFiltersSourceAdapter() {publicHttpFiltersfilterRequest(HttpRequestoriginalRequest,ChannelHandlerContextctx) {returnnewHttpFiltersAdapter(originalRequest) {@OverridepublicHttpResponseclientToProxyRequest(HttpObjecthttpObject) {// TODO: implement your filtering herereturnnull; }@OverridepublicHttpObjectserverToProxyResponse(HttpObjecthttpObject) {// TODO: implement your filtering herereturnhttpObject; } }; } }) .start();
Please refer to the Javadoc oforg.littleshoot.proxy.HttpFilters
to see themethods you can use.
To enable aggregator and inflater you have to return a value greater than 0 inyourHttpFiltersSource#get(Request/Response)BufferSizeInBytes()
methods. Thisprovides to you a `FullHttp(Request/Response)' with the complete content in yourfilter uncompressed. Otherwise you have to handle the chunks yourself.
@OverridepublicintgetMaximumResponseBufferSizeInBytes() {return10 *1024 *1024; }
This size limit applies to every connection. To disable aggregating by URL at*.iso or *dmg files for example, you can return in your filters source a filterlike this:
returnnewHttpFiltersAdapter(originalRequest,serverCtx) {@OverridepublicvoidproxyToServerConnectionSucceeded(ChannelHandlerContextserverCtx) {ChannelPipelinepipeline =serverCtx.pipeline();if (pipeline.get("inflater") !=null) {pipeline.remove("inflater"); }if (pipeline.get("aggregator") !=null) {pipeline.remove("aggregator"); }super.proxyToServerConnectionSucceeded(serverCtx); }};
This enables huge downloads in an application, which regular handles sizelimitedFullHttpResponse
s to modify its content, HTML for example.
A proxy server like LittleProxy contains always a web server, too. If you get anURI without scheme, host and port inoriginalRequest
it's a direct request toyour proxy. You can return aHttpFilters
implementation which answersresponses with HTML content or redirects inclientToProxyRequest
like this:
publicclassAnswerRequestFilterextendsHttpFiltersAdapter {privatefinalStringanswer;publicAnswerRequestFilter(HttpRequestoriginalRequest,Stringanswer) {super(originalRequest,null);this.answer =answer;}@OverridepublicHttpResponseclientToProxyRequest(HttpObjecthttpObject) {ByteBufbuffer =Unpooled.wrappedBuffer(answer.getBytes("UTF-8"));HttpResponseresponse =newDefaultFullHttpResponse(HttpVersion.HTTP_1_1,HttpResponseStatus.OK,buffer);HttpHeaders.setContentLength(response,buffer.readableBytes());HttpHeaders.setHeader(response,HttpHeaders.Names.CONTENT_TYPE,"text/html");returnresponse;}}
On answering a redirect, you should add a Connection: close header, to avoidblocking behavior:
HttpHeaders.setHeader(response,Names.CONNECTION,Values.CLOSE);
With this trick, you can implement an UI to your application very easy.
If you want to create additional proxy servers with similar configuration butlistening on different ports, you can clone an existing server. The clonedservers will share event loops to reduce resource usage and when one clone isstopped, all are stopped.
existingServer.clone().withPort(8081).start()
For examples of configuring logging, seesrc/test/resources/log4j.xml.
If you have questions, please visit our Google Group here:
https://groups.google.com/forum/#!forum/littleproxy2
(The original group athttps://groups.google.com/forum/#!forum/littleproxy isn'taccepting posts from new users. But it's still a great resource if you'researching for older answers.)
To subscribe, send an e-mail toLittleProxy2+subscribe@googlegroups.com.
Many thanks toThe Measurement Factory for theuse ofCo-Advisor for HTTP standardscompliance testing.
About
High performance HTTP proxy originally written by your friends at Lantern and now maintained by volunteer open source programmers. This fork of adamfisk's repository was created in order to keep the project alive.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- Java99.8%
- Shell0.2%