• Stars
    star
    2,062
  • Rank 22,415 (Top 0.5 %)
  • Language
    PHP
  • License
    Apache License 2.0
  • Created almost 14 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

High performance HTTP proxy originally written by your friends at Lantern and now maintained by a stellar group of volunteer open source programmers.

Build Status

LittleProxy is a high performance HTTP proxy written in Java atop Trustin Lee's excellent Netty event-based networking library. It's quite stable, 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/adamfisk/LittleProxy.git
$ cd LittleProxy
$ ./run.bash

You can embed LittleProxy in your own projects through Maven with the following:

    <dependency>
        <groupId>org.littleshoot</groupId>
        <artifactId>littleproxy</artifactId>
        <version>1.1.2</version>
    </dependency>

Once you've included LittleProxy, you can start the server with the following:

HttpProxyServer server =
    DefaultHttpProxyServer.bootstrap()
        .withPort(8080)
        .start();

To intercept and manipulate HTTPS traffic, LittleProxy uses a man-in-the-middle (MITM) manager. LittleProxy's default implementation (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 a HttpFiltersSource(Adapter), for example:

HttpProxyServer server =
    DefaultHttpProxyServer.bootstrap()
        .withPort(8080)
        .withFiltersSource(new HttpFiltersSourceAdapter() {
            public HttpFilters filterRequest(HttpRequest originalRequest, ChannelHandlerContext ctx) {
                return new HttpFiltersAdapter(originalRequest) {
                    @Override
                    public HttpResponse clientToProxyRequest(HttpObject httpObject) {
                        // TODO: implement your filtering here
                        return null;
                    }

                    @Override
                    public HttpObject serverToProxyResponse(HttpObject httpObject) {
                        // TODO: implement your filtering here
                        return httpObject;
                    }
                };
            }
        })
        .start();

Please refer to the Javadoc of org.littleshoot.proxy.HttpFilters to see the methods you can use.

To enable aggregator and inflater you have to return a value greater than 0 in your HttpFiltersSource#get(Request/Response)BufferSizeInBytes() methods. This provides to you a `FullHttp(Request/Response)' with the complete content in your filter uncompressed. Otherwise you have to handle the chunks yourself.

    @Override
    public int getMaximumResponseBufferSizeInBytes() {
        return 10 * 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 filter like this:

return new HttpFiltersAdapter(originalRequest, serverCtx) {
    @Override
    public void proxyToServerConnectionSucceeded(ChannelHandlerContext serverCtx) {
        ChannelPipeline pipeline = 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 size limited FullHttpResponses to modify its content, HTML for example.

A proxy server like LittleProxy contains always a web server, too. If you get an URI without scheme, host and port in originalRequest it's a direct request to your proxy. You can return a HttpFilters implementation which answers responses with HTML content or redirects in clientToProxyRequest like this:

public class AnswerRequestFilter extends HttpFiltersAdapter {
	private final String answer;

	public AnswerRequestFilter(HttpRequest originalRequest, String answer) {
		super(originalRequest, null);
		this.answer = answer;
	}

	@Override
	public HttpResponse clientToProxyRequest(HttpObject httpObject) {
		ByteBuf buffer = Unpooled.wrappedBuffer(answer.getBytes("UTF-8"));
		HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buffer);
		HttpHeaders.setContentLength(response, buffer.readableBytes());
		HttpHeaders.setHeader(response, HttpHeaders.Names.CONTENT_TYPE, "text/html");
		return response;
	}
}

On answering a redirect, you should add a Connection: close header, to avoid blocking 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 but listening on different ports, you can clone an existing server. The cloned servers will share event loops to reduce resource usage and when one clone is stopped, all are stopped.

existingServer.clone().withPort(8081).start()

For examples of configuring logging, see src/test/resources/log4j.xml.

If you have questions, please visit our Google Group here:

https://groups.google.com/forum/#!forum/littleproxy

To subscribe, send an E-Mail to mailto:[email protected]. Simply answering, don't clicking the button, bypasses Googles registration process. You will become a member.

Benchmarking instructions and results can be found here.

Acknowledgments

Many thanks to The Measurement Factory for the use of Co-Advisor for HTTP standards compliance testing.

More Repositories

1

DNSSEC4J

Java Wrapper around DNSSEC primitives in dnsjava
Java
8
star
2

littleshoot-turn-server

TURN Server
Java
8
star
3

littleshoot-stun-client

STUN Client for LittleShoot P2P Platform
Java
6
star
4

littleshoot-p2p

Top level LittleShoot P2P project enabling drop-in use of the LittleShoot P2P platform in your own projects.
Java
6
star
5

littleshoot-turn-client

TURN Client
Java
6
star
6

littleshoot-turn-http-server

TURN to HTTP sever bridge library
Java
6
star
7

littleshoot-sip-stack

Session Initiation Protocol (SIP) Stack
Java
4
star
8

littleshoot-sip-client

Session Initiation Protocol (SIP) Client
Java
4
star
9

littleshoot-downloader

LittleShoot P2P Multi-Source Downloader
Java
3
star
10

littleshoot-portmapping

Java wrapper for UPnP and NAT-PMP port mapping code in LibTorrent
Java
3
star
11

littleshoot-uuid

Fork of http://johannburkard.de/software/uuid/
3
star
12

UDT-File-Server

File Server Built on UDT
Java
2
star
13

littleshoot-stun-stack

LittleShoot Core STUN Stack
Java
2
star
14

littleshoot-sip-server

Session Initiation Protocol (SIP) Server
Java
2
star
15

littleshoot-smack-xmpp

Fork of the Smack XMPP library to fix bugs
Java
2
star
16

littleshoot-xmpp

LittleShoot XMPP Wrapper Code
Java
2
star
17

littleshoot-stun-server

LittleShoot STUN Server
Java
2
star
18

littleshoot-client

LittleShoot Client
JavaScript
2
star
19

dnsjava-fork

Fork of the http://www.dnsjava.org/ project purely to integrate more easily with maven central, GitHub, etc
Java
2
star
20

littleshoot-p2p-sockets

LittleShoot P2P Socket Library
Java
1
star
21

littleshoot-libtorrent

1
star
22

littleshoot-demo

JavaScript
1
star
23

smartfiles

C++
1
star
24

littleshoot-sdp

Session Description Protocol (SDP) Port
Java
1
star
25

littleshoot-commons-id

Fork of Commons ID
Java
1
star
26

littleshoot-npapi

Legacy NPAPI from LittleShoot
C++
1
star
27

littleshoot-mina

Apache Mina port to avoid conflicts with Mina versions in systems embedding LittleShoot
Java
1
star
28

littleshoot-sip-bootstrap

Session Initiation Protocol (SIP) Client Bootstrapping Library
Java
1
star
29

littleshoot-ice

Interactive Connectivity Establishment (ICE) Protocol Implementation for the LittleShoot P2P Platform
Java
1
star
30

littleshoot-smack-xmpp-3-2-2

Fork of Smack XMPP library version 3.2.2
Java
1
star
31

littleshoot-applet-installer

Installer Using a Java Applet
JavaScript
1
star
32

SoChange

Change the World Through Group Buying!
D
1
star
33

littleshoot-net

LittleShoot Network Connectivity
1
star
34

littleshoot-amazon-s3

LittleShoot Amazon S3 utilities
Java
1
star
35

littleshoot-http-client

LittleShoot wrappers around Apache HTTP client
Java
1
star
36

Super-Simple-Signaling

A new super efficient and scalable signaling and presence client/server architecture.
1
star
37

littleshoot-amazon-ec2

LittleShoot Amazon EC2 Utilities
Java
1
star
38

littleshoot-jlibtorrent

Java wrapper around LibTorrent
C++
1
star
39

littleshoot-amazon-stack

LittleShoot core stack for working with Amazon Web Services
Java
1
star
40

littleshoot-sip-http-client

Library for creating sockets negotiated through SIP for use in Apache HTTP Client
Java
1
star
41

littleshoot-offer-answer

Abstraction for a swappable offer/answer protocol layer in the LittleShoot P2P platform
Java
1
star
42

littleshoot-mina-util

LittleShoot Mina Utilities
Java
1
star
43

littleshoot-udt

UDT Port for LittleShoot
Java
1
star
44

littleshoot-util

Utilities for LittleShoot P2P Platform
Java
1
star
45

littleshoot-tcp-framing

LittleShoot TCP Framing Library
Java
1
star
46

GeoIP-Java

Java Interface to MaxMind Database
Java
1
star
47

littleshoot-maven-parent

LittleShoot Maven Parent Pom
Shell
1
star