org.littleshoot.proxy.HttpProxyServerBootstrap Java Examples

The following examples show how to use org.littleshoot.proxy.HttpProxyServerBootstrap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 6 votes vote down vote up
@Override
public HttpProxyServerBootstrap clone() {
    return new DefaultHttpProxyServerBootstrap(serverGroup,
            transportProtocol,
            new InetSocketAddress(requestedAddress.getAddress(),
                    requestedAddress.getPort() == 0 ? 0 : requestedAddress.getPort() + 1),
            sslEngineSource,
            authenticateSslClients,
            proxyAuthenticator,
            chainProxyManager,
            mitmManager,
            filtersSource,
            transparent,
            idleConnectionTimeout,
            activityTrackers,
            connectTimeout,
            serverResolver,
            globalTrafficShapingHandler != null ? globalTrafficShapingHandler.getReadLimit() : 0,
            globalTrafficShapingHandler != null ? globalTrafficShapingHandler.getWriteLimit() : 0,
            localAddress,
            proxyAlias,
            maxInitialLineLength,
            maxHeaderSize,
            maxChunkSize,
            allowRequestsToOriginServer);
}
 
Example #2
Source File: Launcher.java    From LittleProxy-mitm with Apache License 2.0 6 votes vote down vote up
public static void main(final String... args) {
    File log4jConfigurationFile = new File(
            "src/test/resources/log4j.xml");
    if (log4jConfigurationFile.exists()) {
        DOMConfigurator.configureAndWatch(
                log4jConfigurationFile.getAbsolutePath(), 15);
    }
    try {
        final int port = 9090;

        System.out.println("About to start server on port: " + port);
        HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer
                .bootstrapFromFile("./littleproxy.properties")
                .withPort(port).withAllowLocalOnly(false);

        bootstrap.withManInTheMiddle(new CertificateSniffingMitmManager());

        System.out.println("About to start...");
        bootstrap.start();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        System.exit(1);
    }
}
 
Example #3
Source File: Launcher.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
public static void main(final String... args) {
    File log4jConfigurationFile = new File(
            "src/test/resources/log4j.xml");
    if (log4jConfigurationFile.exists()) {
        DOMConfigurator.configureAndWatch(
                log4jConfigurationFile.getAbsolutePath(), 15);
    }
    try {
        final int port = 9090;

        System.out.println("About to start server on port: " + port);
        HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer
                .bootstrapFromFile("./littleproxy.properties")
                .withPort(port).withAllowLocalOnly(false);

        bootstrap.withManInTheMiddle(new CertificateSniffingMitmManager());

        System.out.println("About to start...");
        bootstrap.start();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        System.exit(1);
    }
}
 
Example #4
Source File: Launcher.java    From CapturePacket with MIT License 6 votes vote down vote up
public static void main(final String... args) {
    File log4jConfigurationFile = new File(
            "src/test/resources/log4j.xml");
    if (log4jConfigurationFile.exists()) {
        DOMConfigurator.configureAndWatch(
                log4jConfigurationFile.getAbsolutePath(), 15);
    }
    try {
        final int port = 9090;

        System.out.println("About to start server on port: " + port);
        HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer
                .bootstrapFromFile("./littleproxy.properties")
                .withPort(port).withAllowLocalOnly(false);

        bootstrap.withManInTheMiddle(new CertificateSniffingMitmManager());

        System.out.println("About to start...");
        bootstrap.start();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        System.exit(1);
    }
}
 
Example #5
Source File: ProxyTest.java    From gradle-download-task with Apache License 2.0 5 votes vote down vote up
/**
 * Runs a proxy server counting requests
 * @param authenticating true if the proxy should require authentication
 * @throws Exception if an error occurred
 */
private void startProxy(boolean authenticating) throws Exception {
    proxyPort = findPort();
    
    HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer.bootstrap()
            .withPort(proxyPort)
            .withFiltersSource(new HttpFiltersSourceAdapter() {
                public HttpFilters filterRequest(HttpRequest originalRequest,
                        ChannelHandlerContext ctx) {
                   return new HttpFiltersAdapter(originalRequest) {
                      @Override
                      public void proxyToServerRequestSent() {
                          proxyCounter++;
                      }
                   };
                }
            });
    
    if (authenticating) {
        bootstrap = bootstrap.withProxyAuthenticator(new ProxyAuthenticator() {
            @Override
            public boolean authenticate(String userName, String password) {
                return PROXY_USERNAME.equals(userName) &&
                        PROXY_PASSWORD.equals(password);
            }

            @Override
            public String getRealm() {
                return "gradle-download-task";
            }
        });
    }
    
    proxy = bootstrap.start();
}
 
Example #6
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 5 votes vote down vote up
/**
 * Bootstrap a new {@link DefaultHttpProxyServer} using defaults from the
 * given file.
 *
 * @param path
 * @return
 */
public static HttpProxyServerBootstrap bootstrapFromFile(String path) {
    final File propsFile = new File(path);
    Properties props = new Properties();

    if (propsFile.isFile()) {
        try (InputStream is = new FileInputStream(propsFile)) {
            props.load(is);
        } catch (final IOException e) {
            LOG.warn("Could not load props file?", e);
        }
    }

    return new DefaultHttpProxyServerBootstrap(props);
}
 
Example #7
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 5 votes vote down vote up
@Override
public HttpProxyServerBootstrap withThreadPoolConfiguration(ThreadPoolConfiguration configuration) {
    this.clientToProxyAcceptorThreads = configuration.getAcceptorThreads();
    this.clientToProxyWorkerThreads = configuration.getClientToProxyWorkerThreads();
    this.proxyToServerWorkerThreads = configuration.getProxyToServerWorkerThreads();
    return this;
}
 
Example #8
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 5 votes vote down vote up
@Override
public HttpProxyServerBootstrap withUseDnsSec(boolean useDnsSec) {
    if (useDnsSec) {
        this.serverResolver = new DnsSecServerResolver();
    } else {
        this.serverResolver = new DefaultHostResolver();
    }
    return this;
}
 
Example #9
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 5 votes vote down vote up
@Override
public HttpProxyServerBootstrap withManInTheMiddle(
        MitmManager mitmManager) {
    this.mitmManager = mitmManager;
    if (this.sslEngineSource != null) {
        LOG.warn("Enabled man in the middle with encrypted inbound connections. "
                + "These are mutually exclusive - encrypted inbound connections will be disabled.");
        this.sslEngineSource = null;
    }
    return this;
}
 
Example #10
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 5 votes vote down vote up
@Override
public HttpProxyServerBootstrap withSslEngineSource(
        SslEngineSource sslEngineSource) {
    this.sslEngineSource = sslEngineSource;
    if (this.mitmManager != null) {
        LOG.warn("Enabled encrypted inbound connections with man in the middle. "
                + "These are mutually exclusive - man in the middle will be disabled.");
        this.mitmManager = null;
    }
    return this;
}
 
Example #11
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withConnectTimeout(
        int connectTimeout) {
    this.connectTimeout = connectTimeout;
    return this;
}
 
Example #12
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withFiltersSource(
        HttpFiltersSource filtersSource) {
    this.filtersSource = filtersSource;
    return this;
}
 
Example #13
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withServerResolver(
        HostResolver serverResolver) {
    this.serverResolver = serverResolver;
    return this;
}
 
Example #14
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap plusActivityTracker(
        ActivityTracker activityTracker) {
    activityTrackers.add(activityTracker);
    return this;
}
 
Example #15
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withThrottling(long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond) {
    this.readThrottleBytesPerSecond = readThrottleBytesPerSecond;
    this.writeThrottleBytesPerSecond = writeThrottleBytesPerSecond;
    return this;
}
 
Example #16
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withMaxInitialLineLength(int maxInitialLineLength) {
    this.maxInitialLineLength = maxInitialLineLength;
    return this;
}
 
Example #17
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withMaxHeaderSize(int maxHeaderSize) {
    this.maxHeaderSize = maxHeaderSize;
    return this;
}
 
Example #18
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withMaxChunkSize(int maxChunkSize) {
    this.maxChunkSize = maxChunkSize;
    return this;
}
 
Example #19
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withAllowRequestToOriginServer(boolean allowRequestToOriginServer) {
    this.allowRequestToOriginServer = allowRequestToOriginServer;
    return this;
}
 
Example #20
Source File: Proxy.java    From LittleProxy-mitm with Apache License 2.0 4 votes vote down vote up
protected HttpProxyServerBootstrap bootstrap() {
    return DefaultHttpProxyServer.bootstrap().withPort(proxyPort);
}
 
Example #21
Source File: HttpProxyTest.java    From java-cloudant with Apache License 2.0 4 votes vote down vote up
/**
 * Starts a littleproxy instance that will proxy the requests. Applies appropriate configuration
 * options to the proxy based on the test parameters.
 *
 * @throws Exception
 */
@BeforeEach
public void setupAndStartProxy(final boolean okUsable,
                               final boolean useSecureProxy,
                               final boolean useHttpsServer,
                               final boolean useProxyAuth) throws Exception {

    HttpProxyServerBootstrap proxyBoostrap = DefaultHttpProxyServer.bootstrap()
            .withAllowLocalOnly(true) // only run on localhost
            .withAuthenticateSslClients(false); // we aren't checking client certs

    if (useProxyAuth) {
        // check the proxy user and password
        ProxyAuthenticator pa = new ProxyAuthenticator() {
            @Override
            public boolean authenticate(String userName, String password) {
                return (mockProxyUser.equals(userName) && mockProxyPass.equals(password));
            }

            @Override
            public String getRealm() {
                return null;
            }
        };
        proxyBoostrap.withProxyAuthenticator(pa);
    }

    if (useSecureProxy) {
        proxyBoostrap.withSslEngineSource(new SslEngineSource() {
            @Override
            public SSLEngine newSslEngine() {
                return MockWebServerResources.getSSLContext().createSSLEngine();
            }

            @Override
            public SSLEngine newSslEngine(String peerHost, int peerPort) {
                return MockWebServerResources.getSSLContext().createSSLEngine(peerHost,
                        peerPort);
            }
        });
    }

    // Start the proxy server
    proxy = proxyBoostrap.start();
}
 
Example #22
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withIdleConnectionTimeout(
        int idleConnectionTimeout) {
    this.idleConnectionTimeout = idleConnectionTimeout;
    return this;
}
 
Example #23
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withTransparent(
        boolean transparent) {
    this.transparent = transparent;
    return this;
}
 
Example #24
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withChainProxyManager(
        ChainedProxyManager chainProxyManager) {
    this.chainProxyManager = chainProxyManager;
    return this;
}
 
Example #25
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withProxyAuthenticator(
        ProxyAuthenticator proxyAuthenticator) {
    this.proxyAuthenticator = proxyAuthenticator;
    return this;
}
 
Example #26
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withAuthenticateSslClients(
        boolean authenticateSslClients) {
    this.authenticateSslClients = authenticateSslClients;
    return this;
}
 
Example #27
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
@Deprecated
public HttpProxyServerBootstrap withListenOnAllAddresses(boolean listenOnAllAddresses) {
    LOG.warn("withListenOnAllAddresses() is deprecated and will be removed in a future release. Use withNetworkInterface().");
    return this;
}
 
Example #28
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withAllowLocalOnly(
        boolean allowLocalOnly) {
    this.allowLocalOnly = allowLocalOnly;
    return this;
}
 
Example #29
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withProxyAlias(String alias) {
    this.proxyAlias = alias;
    return this;
}
 
Example #30
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
@Override
public HttpProxyServerBootstrap withNetworkInterface(InetSocketAddress inetSocketAddress) {
    this.localAddress = inetSocketAddress;
    return this;
}