org.littleshoot.proxy.HttpFilters Java Examples

The following examples show how to use org.littleshoot.proxy.HttpFilters. 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: BrowserUpHttpFilterChain.java    From browserup-proxy with Apache License 2.0 6 votes vote down vote up
@Override
public HttpObject proxyToClientResponse(HttpObject httpObject) {
    HttpObject processedHttpObject = httpObject;
    for (HttpFilters filter : filters) {
        try {
            processedHttpObject = filter.proxyToClientResponse(processedHttpObject);
            if (processedHttpObject == null) {
                return null;
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return processedHttpObject;
}
 
Example #2
Source File: BrowserMobHttpFilterChain.java    From Dream-Catcher with MIT License 6 votes vote down vote up
@Override
public InetSocketAddress proxyToServerResolutionStarted(String resolvingServerHostAndPort) {
    InetSocketAddress overrideAddress = null;
    String newServerHostAndPort = resolvingServerHostAndPort;

    for (HttpFilters filter : filters) {
        try {
            InetSocketAddress filterResult = filter.proxyToServerResolutionStarted(newServerHostAndPort);
            if (filterResult != null) {
                overrideAddress = filterResult;
                newServerHostAndPort = filterResult.getHostString() + ":" + filterResult.getPort();
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return overrideAddress;
}
 
Example #3
Source File: BrowserMobHttpFilterChain.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
@Override
public HttpObject proxyToClientResponse(HttpObject httpObject) {
    HttpObject processedHttpObject = httpObject;
    for (HttpFilters filter : filters) {
        try {
            processedHttpObject = filter.proxyToClientResponse(processedHttpObject);
            if (processedHttpObject == null) {
                return null;
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return processedHttpObject;
}
 
Example #4
Source File: BrowserMobHttpFilterChain.java    From CapturePacket with MIT License 6 votes vote down vote up
@Override
public InetSocketAddress proxyToServerResolutionStarted(String resolvingServerHostAndPort) {
    InetSocketAddress overrideAddress = null;
    String newServerHostAndPort = resolvingServerHostAndPort;

    for (HttpFilters filter : filters) {
        try {
            InetSocketAddress filterResult = filter.proxyToServerResolutionStarted(newServerHostAndPort);
            if (filterResult != null) {
                overrideAddress = filterResult;
                newServerHostAndPort = filterResult.getHostString() + ":" + filterResult.getPort();
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return overrideAddress;
}
 
Example #5
Source File: BrowserMobHttpFilterChain.java    From Dream-Catcher with MIT License 6 votes vote down vote up
@Override
public HttpObject proxyToClientResponse(HttpObject httpObject) {
    HttpObject processedHttpObject = httpObject;
    for (HttpFilters filter : filters) {
        try {
            processedHttpObject = filter.proxyToClientResponse(processedHttpObject);
            if (processedHttpObject == null) {
                return null;
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return processedHttpObject;
}
 
Example #6
Source File: BrowserMobHttpFilterChain.java    From CapturePacket with MIT License 6 votes vote down vote up
public BrowserMobHttpFilterChain(BrowserMobProxyServer proxyServer, HttpRequest originalRequest, ChannelHandlerContext ctx) {
    super(originalRequest, ctx);

    this.proxyServer = proxyServer;

    if (proxyServer.getFilterFactories() != null) {
        filters = new ArrayList<>(proxyServer.getFilterFactories().size());

        // instantiate all HttpFilters using the proxy's filter factories
        for (HttpFiltersSource filterFactory : proxyServer.getFilterFactories()) {
            HttpFilters filter = filterFactory.filterRequest(originalRequest, ctx);
            // allow filter factories to avoid adding a filter on a per-request basis by returning a null
            // HttpFilters instance
            if (filter != null) {
                filters.add(filter);
            }
        }
    } else {
        filters = Collections.emptyList();
    }
}
 
Example #7
Source File: BrowserMobHttpFilterChain.java    From CapturePacket with MIT License 6 votes vote down vote up
@Override
public HttpObject proxyToClientResponse(HttpObject httpObject) {
    HttpObject processedHttpObject = httpObject;
    for (HttpFilters filter : filters) {
        try {
            processedHttpObject = filter.proxyToClientResponse(processedHttpObject);
            if (processedHttpObject == null) {
                return null;
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return processedHttpObject;
}
 
Example #8
Source File: BrowserMobHttpFilterChain.java    From Dream-Catcher with MIT License 6 votes vote down vote up
@Override
public HttpObject serverToProxyResponse(HttpObject httpObject) {
    HttpObject processedHttpObject = httpObject;

    for (HttpFilters filter : filters) {
        try {
            processedHttpObject = filter.serverToProxyResponse(processedHttpObject);
            if (processedHttpObject == null) {
                return null;
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return processedHttpObject;
}
 
Example #9
Source File: BrowserMobHttpFilterChain.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
public BrowserMobHttpFilterChain(BrowserMobProxyServer proxyServer, HttpRequest originalRequest, ChannelHandlerContext ctx) {
    super(originalRequest, ctx);

    this.proxyServer = proxyServer;

    if (proxyServer.getFilterFactories() != null) {
        filters = new ArrayList<>(proxyServer.getFilterFactories().size());

        // instantiate all HttpFilters using the proxy's filter factories
        for (HttpFiltersSource filterFactory : proxyServer.getFilterFactories()) {
            HttpFilters filter = filterFactory.filterRequest(originalRequest, ctx);
            // allow filter factories to avoid adding a filter on a per-request basis by returning a null
            // HttpFilters instance
            if (filter != null) {
                filters.add(filter);
            }
        }
    } else {
        filters = Collections.emptyList();
    }
}
 
Example #10
Source File: BrowserUpHttpFilterChain.java    From browserup-proxy with Apache License 2.0 6 votes vote down vote up
@Override
public InetSocketAddress proxyToServerResolutionStarted(String resolvingServerHostAndPort) {
    InetSocketAddress overrideAddress = null;
    String newServerHostAndPort = resolvingServerHostAndPort;

    for (HttpFilters filter : filters) {
        try {
            InetSocketAddress filterResult = filter.proxyToServerResolutionStarted(newServerHostAndPort);
            if (filterResult != null) {
                overrideAddress = filterResult;
                newServerHostAndPort = filterResult.getHostString() + ":" + filterResult.getPort();
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return overrideAddress;
}
 
Example #11
Source File: BrowserUpHttpFilterChain.java    From browserup-proxy with Apache License 2.0 6 votes vote down vote up
@Override
public HttpObject serverToProxyResponse(HttpObject httpObject) {
    HttpObject processedHttpObject = httpObject;

    for (HttpFilters filter : filters) {
        try {
            processedHttpObject = filter.serverToProxyResponse(processedHttpObject);
            if (processedHttpObject == null) {
                return null;
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return processedHttpObject;
}
 
Example #12
Source File: BrowserMobHttpFilterChain.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
@Override
public HttpObject serverToProxyResponse(HttpObject httpObject) {
    HttpObject processedHttpObject = httpObject;

    for (HttpFilters filter : filters) {
        try {
            processedHttpObject = filter.serverToProxyResponse(processedHttpObject);
            if (processedHttpObject == null) {
                return null;
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return processedHttpObject;
}
 
Example #13
Source File: BrowserMobHttpFilterChain.java    From Dream-Catcher with MIT License 6 votes vote down vote up
public BrowserMobHttpFilterChain(BrowserMobProxyServer proxyServer, HttpRequest originalRequest, ChannelHandlerContext ctx) {
    super(originalRequest, ctx);

    this.proxyServer = proxyServer;

    if (proxyServer.getFilterFactories() != null) {
        filters = new ArrayList<>(proxyServer.getFilterFactories().size());

        // instantiate all HttpFilters using the proxy's filter factories
        for (HttpFiltersSource filterFactory : proxyServer.getFilterFactories()) {
            HttpFilters filter = filterFactory.filterRequest(originalRequest, ctx);
            // allow filter factories to avoid adding a filter on a per-request basis by returning a null
            // HttpFilters instance
            if (filter != null) {
                filters.add(filter);
            }
        }
    } else {
        filters = Collections.emptyList();
    }
}
 
Example #14
Source File: ProxyToServerConnection.java    From g4proxy with Apache License 2.0 6 votes vote down vote up
private ProxyToServerConnection(
        DefaultHttpProxyServer proxyServer,
        ClientToProxyConnection clientConnection,
        String serverHostAndPort,
        ChainedProxy chainedProxy,
        Queue<ChainedProxy> availableChainedProxies,
        HttpFilters initialFilters,
        GlobalTrafficShapingHandler globalTrafficShapingHandler)
        throws UnknownHostException {
    super(DISCONNECTED, proxyServer, true);
    this.clientConnection = clientConnection;
    this.serverHostAndPort = serverHostAndPort;
    this.chainedProxy = chainedProxy;
    this.availableChainedProxies = availableChainedProxies;
    this.trafficHandler = globalTrafficShapingHandler;
    this.currentFilters = initialFilters;

    // Report connection status to HttpFilters
    currentFilters.proxyToServerConnectionQueued();

    setupConnectionParameters();
}
 
Example #15
Source File: BrowserMobHttpFilterChain.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
@Override
public InetSocketAddress proxyToServerResolutionStarted(String resolvingServerHostAndPort) {
    InetSocketAddress overrideAddress = null;
    String newServerHostAndPort = resolvingServerHostAndPort;

    for (HttpFilters filter : filters) {
        try {
            InetSocketAddress filterResult = filter.proxyToServerResolutionStarted(newServerHostAndPort);
            if (filterResult != null) {
                overrideAddress = filterResult;
                newServerHostAndPort = filterResult.getHostString() + ":" + filterResult.getPort();
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return overrideAddress;
}
 
Example #16
Source File: ProxyToServerConnection.java    From yfs with Apache License 2.0 6 votes vote down vote up
private ProxyToServerConnection(
        DefaultHttpProxyServer proxyServer,
        ClientToProxyConnection clientConnection,
        String serverHostAndPort,
        ChainedProxy chainedProxy,
        Queue<ChainedProxy> availableChainedProxies,
        HttpFilters initialFilters,
        GlobalTrafficShapingHandler globalTrafficShapingHandler)
        throws UnknownHostException {
    super(DISCONNECTED, proxyServer, true);
    this.clientConnection = clientConnection;
    this.serverHostAndPort = serverHostAndPort;
    this.chainedProxy = chainedProxy;
    this.availableChainedProxies = availableChainedProxies;
    this.trafficHandler = globalTrafficShapingHandler;
    this.currentFilters = initialFilters;

    // Report connection status to HttpFilters
    currentFilters.proxyToServerConnectionQueued();

    setupConnectionParameters();
}
 
Example #17
Source File: ProxyToServerConnection.java    From PowerTunnel with MIT License 6 votes vote down vote up
private ProxyToServerConnection(
        DefaultHttpProxyServer proxyServer,
        ClientToProxyConnection clientConnection,
        String serverHostAndPort,
        ChainedProxy chainedProxy,
        Queue<ChainedProxy> availableChainedProxies,
        HttpFilters initialFilters,
        GlobalTrafficShapingHandler globalTrafficShapingHandler)
        throws UnknownHostException {
    super(DISCONNECTED, proxyServer, true);
    this.clientConnection = clientConnection;
    this.serverHostAndPort = serverHostAndPort;
    this.chainedProxy = chainedProxy;
    this.availableChainedProxies = availableChainedProxies;
    this.trafficHandler = globalTrafficShapingHandler;
    this.currentFilters = initialFilters;

    // Report connection status to HttpFilters
    currentFilters.proxyToServerConnectionQueued();

    setupConnectionParameters();
}
 
Example #18
Source File: BrowserMobHttpFilterChain.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
@Override
public void serverToProxyResponseTimedOut() {
    for (HttpFilters filter : filters) {
        try {
            filter.serverToProxyResponseTimedOut();
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }
}
 
Example #19
Source File: BrowserMobHttpFilterChain.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
@Override
public HttpResponse proxyToServerRequest(HttpObject httpObject) {
    for (HttpFilters filter : filters) {
        try {
            HttpResponse filterResponse = filter.proxyToServerRequest(httpObject);
            if (filterResponse != null) {
                return filterResponse;
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return null;
}
 
Example #20
Source File: BrowserMobHttpFilterChain.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void proxyToServerConnectionStarted() {
    for (HttpFilters filter : filters) {
        try {
            filter.proxyToServerConnectionStarted();
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }
}
 
Example #21
Source File: BrowserMobHttpFilterChain.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
@Override
public void proxyToServerRequestSending() {
    for (HttpFilters filter : filters) {
        try {
            filter.proxyToServerRequestSending();
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }
}
 
Example #22
Source File: BrowserMobHttpFilterChain.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void proxyToServerResolutionSucceeded(String serverHostAndPort, InetSocketAddress resolvedRemoteAddress) {
    for (HttpFilters filter : filters) {
        try {
            filter.proxyToServerResolutionSucceeded(serverHostAndPort, resolvedRemoteAddress);
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    super.proxyToServerResolutionSucceeded(serverHostAndPort, resolvedRemoteAddress);
}
 
Example #23
Source File: ProxyToServerConnection.java    From yfs with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new ProxyToServerConnection.
 *
 * @param proxyServer
 * @param clientConnection
 * @param serverHostAndPort
 * @param initialFilters
 * @param initialHttpRequest
 * @return
 * @throws UnknownHostException
 */
static ProxyToServerConnection create(DefaultHttpProxyServer proxyServer,
                                      ClientToProxyConnection clientConnection,
                                      String serverHostAndPort,
                                      HttpFilters initialFilters,
                                      HttpRequest initialHttpRequest,
                                      GlobalTrafficShapingHandler globalTrafficShapingHandler)
        throws UnknownHostException {
    Queue<ChainedProxy> chainedProxies = new ConcurrentLinkedQueue<ChainedProxy>();
    ChainedProxyManager chainedProxyManager = proxyServer
            .getChainProxyManager();
    if (chainedProxyManager != null) {
        chainedProxyManager.lookupChainedProxies(initialHttpRequest,
                chainedProxies);
        if (chainedProxies.size() == 0) {
            // ChainedProxyManager returned no proxies, can't connect
            return null;
        }
    }
    return new ProxyToServerConnection(proxyServer,
            clientConnection,
            serverHostAndPort,
            chainedProxies.poll(),
            chainedProxies,
            initialFilters,
            globalTrafficShapingHandler);
}
 
Example #24
Source File: BrowserMobHttpFilterChain.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void proxyToServerResolutionFailed(String hostAndPort) {
    for (HttpFilters filter : filters) {
        try {
            filter.proxyToServerResolutionFailed(hostAndPort);
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }
}
 
Example #25
Source File: BrowserMobHttpFilterChain.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void serverToProxyResponseReceiving() {
    for (HttpFilters filter : filters) {
        try {
            filter.serverToProxyResponseReceiving();
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }
}
 
Example #26
Source File: BrowserMobHttpFilterChain.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void serverToProxyResponseTimedOut() {
    for (HttpFilters filter : filters) {
        try {
            filter.serverToProxyResponseTimedOut();
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }
}
 
Example #27
Source File: BrowserMobHttpFilterChain.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void proxyToServerRequestSending() {
    for (HttpFilters filter : filters) {
        try {
            filter.proxyToServerRequestSending();
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }
}
 
Example #28
Source File: BrowserMobHttpFilterChain.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public HttpResponse proxyToServerRequest(HttpObject httpObject) {
    for (HttpFilters filter : filters) {
        try {
            HttpResponse filterResponse = filter.proxyToServerRequest(httpObject);
            if (filterResponse != null) {
                return filterResponse;
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    return null;
}
 
Example #29
Source File: BrowserMobHttpFilterChain.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
    if (proxyServer.isStopped()) {
        log.warn("Aborting request to {} because proxy is stopped", originalRequest.getUri());
        HttpResponse abortedResponse = new DefaultFullHttpResponse(originalRequest.getProtocolVersion(), HttpResponseStatus.SERVICE_UNAVAILABLE);
        HttpHeaders.setContentLength(abortedResponse, 0L);
        return abortedResponse;
    }

    for (HttpFilters filter : filters) {
        try {
            HttpResponse filterResponse = filter.clientToProxyRequest(httpObject);
            if (filterResponse != null) {
                // if we are short-circuiting the response to an HttpRequest, update ModifiedRequestAwareFilter instances
                // with this (possibly) modified HttpRequest before returning the short-circuit response
                if (httpObject instanceof HttpRequest) {
                    updateFiltersWithModifiedResponse((HttpRequest) httpObject);
                }

                return filterResponse;
            }
        } catch (RuntimeException e) {
            log.warn("Filter in filter chain threw exception. Filter method may have been aborted.", e);
        }
    }

    // if this httpObject is the HTTP request, set the modified request object on all ModifiedRequestAwareFilter
    // instances, so they have access to all modifications the request filters made while filtering
    if (httpObject instanceof HttpRequest) {
        updateFiltersWithModifiedResponse((HttpRequest) httpObject);
    }

    return null;
}
 
Example #30
Source File: ProxyToServerConnection.java    From PowerTunnel with MIT License 5 votes vote down vote up
/**
 * Create a new ProxyToServerConnection.
 */
static ProxyToServerConnection create(DefaultHttpProxyServer proxyServer,
                                      ClientToProxyConnection clientConnection,
                                      String serverHostAndPort,
                                      HttpFilters initialFilters,
                                      HttpRequest initialHttpRequest,
                                      GlobalTrafficShapingHandler globalTrafficShapingHandler)
        throws UnknownHostException {
    Queue<ChainedProxy> chainedProxies = new ConcurrentLinkedQueue<>();
    ChainedProxyManager chainedProxyManager = proxyServer
            .getChainProxyManager();
    if (chainedProxyManager != null) {
        chainedProxyManager.lookupChainedProxies(initialHttpRequest,
                chainedProxies, clientConnection.getClientDetails());
        if (chainedProxies.size() == 0) {
            // ChainedProxyManager returned no proxies, can't connect
            return null;
        }
    }
    return new ProxyToServerConnection(proxyServer,
            clientConnection,
            serverHostAndPort,
            chainedProxies.poll(),
            chainedProxies,
            initialFilters,
            globalTrafficShapingHandler);
}