Search in sources :

Example 1 with HttpFilters

use of org.littleshoot.proxy.HttpFilters in project td-client-java by treasure-data.

the class TestProxyAccess method setUp.

@Before
public void setUp() throws Exception {
    proxyAccessCount.set(0);
    this.proxyPort = findAvailablePort();
    this.proxyServer = DefaultHttpProxyServer.bootstrap().withPort(proxyPort).withProxyAuthenticator(new org.littleshoot.proxy.ProxyAuthenticator() {

        @Override
        public boolean authenticate(String user, String pass) {
            boolean isValid = user.equals(PROXY_USER) && pass.equals(PROXY_PASS);
            logger.debug("Proxy Authentication: " + (isValid ? "success" : "failure"));
            return isValid;
        }
    }).withFiltersSource(new HttpFiltersSourceAdapter() {

        @Override
        public HttpFilters filterRequest(HttpRequest httpRequest, ChannelHandlerContext channelHandlerContext) {
            proxyAccessCount.incrementAndGet();
            return super.filterRequest(httpRequest, channelHandlerContext);
        }
    }).start();
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpFiltersSourceAdapter(org.littleshoot.proxy.HttpFiltersSourceAdapter) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpFilters(org.littleshoot.proxy.HttpFilters) Before(org.junit.Before)

Example 2 with HttpFilters

use of org.littleshoot.proxy.HttpFilters in project td-client-java by treasure-data.

the class TestSSLProxyAccess method setUp.

@Before
public void setUp() throws Exception {
    proxyAccessCount.set(0);
    this.proxyPort = TestProxyAccess.findAvailablePort();
    this.proxyServer = DefaultHttpProxyServer.bootstrap().withPort(proxyPort).withProxyAuthenticator(new org.littleshoot.proxy.ProxyAuthenticator() {

        public boolean authenticate(String user, String pass) {
            boolean isValid = user.equals(PROXY_USER) && pass.equals(PROXY_PASS);
            logger.debug("Proxy Authentication: " + (isValid ? "success" : "failure"));
            return isValid;
        }
    }).withFiltersSource(new HttpFiltersSourceAdapter() {

        @Override
        public HttpFilters filterRequest(HttpRequest httpRequest, ChannelHandlerContext channelHandlerContext) {
            proxyAccessCount.incrementAndGet();
            return super.filterRequest(httpRequest, channelHandlerContext);
        }
    }).start();
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpFiltersSourceAdapter(org.littleshoot.proxy.HttpFiltersSourceAdapter) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpFilters(org.littleshoot.proxy.HttpFilters) Before(org.junit.Before)

Aggregations

ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 HttpRequest (io.netty.handler.codec.http.HttpRequest)2 Before (org.junit.Before)2 HttpFilters (org.littleshoot.proxy.HttpFilters)2 HttpFiltersSourceAdapter (org.littleshoot.proxy.HttpFiltersSourceAdapter)2