org.littleshoot.proxy.HttpFiltersSource Java Examples

The following examples show how to use org.littleshoot.proxy.HttpFiltersSource. 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: ProxyTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Test
void testClearRequestFilters()
{
    configureProxy();
    BrowserUpProxyServer browserMobProxyServer = mock(BrowserUpProxyServer.class);
    ResponseFilter responseFilter = mock(ResponseFilter.class);
    RequestFilter requestFilter = mock(RequestFilter.class);
    ResponseFilterAdapter.FilterSource fsResponse = new ResponseFilterAdapter.FilterSource(responseFilter);
    RequestFilterAdapter.FilterSource fsRequest = new RequestFilterAdapter.FilterSource(requestFilter);
    when(proxyServerFactory.createProxyServer()).thenReturn(browserMobProxyServer);
    List<HttpFiltersSource> toRemove = new ArrayList<>();
    toRemove.add(fsResponse);
    toRemove.add(fsRequest);
    when(browserMobProxyServer.getFilterFactories()).thenReturn(toRemove).thenReturn(toRemove);
    proxy.start();
    proxy.clearRequestFilters();
    assertTrue(toRemove.size() == 1 && toRemove.contains(fsResponse));
}
 
Example #2
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 #3
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 #4
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 #5
Source File: Proxy.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Override
public void clearRequestFilters()
{
    List<HttpFiltersSource> toRemove = new ArrayList<>();
    for (HttpFiltersSource source : ((BrowserUpProxyServer) proxyServer).getFilterFactories())
    {
        if (source instanceof FilterSource)
        {
            toRemove.add(source);
        }
    }
    ((BrowserUpProxyServer) proxyServer).getFilterFactories().removeAll(toRemove);
}
 
Example #6
Source File: BrowserUpProxyServer.java    From browserup-proxy with Apache License 2.0 5 votes vote down vote up
private int getMaximumRequestBufferSize() {
    int maxBufferSize = 0;
    for (HttpFiltersSource source : filterFactories) {
        int requestBufferSize = source.getMaximumRequestBufferSizeInBytes();
        if (requestBufferSize > maxBufferSize) {
            maxBufferSize = requestBufferSize;
        }
    }

    return maxBufferSize;
}
 
Example #7
Source File: BrowserUpProxyServer.java    From browserup-proxy with Apache License 2.0 5 votes vote down vote up
private int getMaximumResponseBufferSize() {
    int maxBufferSize = 0;
    for (HttpFiltersSource source : filterFactories) {
        int requestBufferSize = source.getMaximumResponseBufferSizeInBytes();
        if (requestBufferSize > maxBufferSize) {
            maxBufferSize = requestBufferSize;
        }
    }

    return maxBufferSize;
}
 
Example #8
Source File: BrowserMobProxyServer.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
private int getMaximumResponseBufferSize() {
    int maxBufferSize = 0;
    for (HttpFiltersSource source : filterFactories) {
        int requestBufferSize = source.getMaximumResponseBufferSizeInBytes();
        if (requestBufferSize > maxBufferSize) {
            maxBufferSize = requestBufferSize;
        }
    }

    return maxBufferSize;
}
 
Example #9
Source File: BrowserMobProxyServer.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
private int getMaximumRequestBufferSize() {
    int maxBufferSize = 0;
    for (HttpFiltersSource source : filterFactories) {
        int requestBufferSize = source.getMaximumRequestBufferSizeInBytes();
        if (requestBufferSize > maxBufferSize) {
            maxBufferSize = requestBufferSize;
        }
    }

    return maxBufferSize;
}
 
Example #10
Source File: BrowserMobProxyServer.java    From Dream-Catcher with MIT License 5 votes vote down vote up
private int getMaximumResponseBufferSize() {
    int maxBufferSize = 0;
    for (HttpFiltersSource source : filterFactories) {
        int requestBufferSize = source.getMaximumResponseBufferSizeInBytes();
        if (requestBufferSize > maxBufferSize) {
            maxBufferSize = requestBufferSize;
        }
    }

    return maxBufferSize;
}
 
Example #11
Source File: BrowserMobProxyServer.java    From CapturePacket with MIT License 5 votes vote down vote up
private int getMaximumRequestBufferSize() {
    int maxBufferSize = 0;
    for (HttpFiltersSource source : filterFactories) {
        int requestBufferSize = source.getMaximumRequestBufferSizeInBytes();
        if (requestBufferSize > maxBufferSize) {
            maxBufferSize = requestBufferSize;
        }
    }

    return maxBufferSize;
}
 
Example #12
Source File: BrowserMobProxyServer.java    From CapturePacket with MIT License 5 votes vote down vote up
private int getMaximumResponseBufferSize() {
    int maxBufferSize = 0;
    for (HttpFiltersSource source : filterFactories) {
        int requestBufferSize = source.getMaximumResponseBufferSizeInBytes();
        if (requestBufferSize > maxBufferSize) {
            maxBufferSize = requestBufferSize;
        }
    }

    return maxBufferSize;
}
 
Example #13
Source File: BrowserMobProxyServer.java    From Dream-Catcher with MIT License 5 votes vote down vote up
private int getMaximumRequestBufferSize() {
    int maxBufferSize = 0;
    for (HttpFiltersSource source : filterFactories) {
        int requestBufferSize = source.getMaximumRequestBufferSizeInBytes();
        if (requestBufferSize > maxBufferSize) {
            maxBufferSize = requestBufferSize;
        }
    }

    return maxBufferSize;
}
 
Example #14
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 #15
Source File: DefaultHttpProxyServer.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
private DefaultHttpProxyServerBootstrap(
        ServerGroup serverGroup,
        TransportProtocol transportProtocol,
        InetSocketAddress requestedAddress,
        SslEngineSource sslEngineSource,
        boolean authenticateSslClients,
        ProxyAuthenticator proxyAuthenticator,
        ChainedProxyManager chainProxyManager,
        MitmManager mitmManager,
        HttpFiltersSource filtersSource,
        boolean transparent, int idleConnectionTimeout,
        Collection<ActivityTracker> activityTrackers,
        int connectTimeout, HostResolver serverResolver,
        long readThrottleBytesPerSecond,
        long writeThrottleBytesPerSecond,
        InetSocketAddress localAddress,
        String proxyAlias,
        int maxInitialLineLength,
        int maxHeaderSize,
        int maxChunkSize,
        boolean allowRequestToOriginServer) {
    this.serverGroup = serverGroup;
    this.transportProtocol = transportProtocol;
    this.requestedAddress = requestedAddress;
    this.port = requestedAddress.getPort();
    this.sslEngineSource = sslEngineSource;
    this.authenticateSslClients = authenticateSslClients;
    this.proxyAuthenticator = proxyAuthenticator;
    this.chainProxyManager = chainProxyManager;
    this.mitmManager = mitmManager;
    this.filtersSource = filtersSource;
    this.transparent = transparent;
    this.idleConnectionTimeout = idleConnectionTimeout;
    if (activityTrackers != null) {
        this.activityTrackers.addAll(activityTrackers);
    }
    this.connectTimeout = connectTimeout;
    this.serverResolver = serverResolver;
    this.readThrottleBytesPerSecond = readThrottleBytesPerSecond;
    this.writeThrottleBytesPerSecond = writeThrottleBytesPerSecond;
    this.localAddress = localAddress;
    this.proxyAlias = proxyAlias;
    this.maxInitialLineLength = maxInitialLineLength;
    this.maxHeaderSize = maxHeaderSize;
    this.maxChunkSize = maxChunkSize;
    this.allowRequestToOriginServer = allowRequestToOriginServer;
}
 
Example #16
Source File: BrowserMobProxyServer.java    From Dream-Catcher with MIT License 4 votes vote down vote up
@Override
public void addFirstHttpFilterFactory(HttpFiltersSource filterFactory) {
    filterFactories.add(0, filterFactory);
}
 
Example #17
Source File: BrowserMobProxyServer.java    From Dream-Catcher with MIT License 4 votes vote down vote up
@Override
public void addLastHttpFilterFactory(HttpFiltersSource filterFactory) {
    filterFactories.add(filterFactory);
}
 
Example #18
Source File: BrowserMobProxyServer.java    From Dream-Catcher with MIT License 4 votes vote down vote up
public void addHttpFilterFactory(HttpFiltersSource filterFactory) {
    filterFactories.add(filterFactory);
}
 
Example #19
Source File: BrowserMobProxyServer.java    From Dream-Catcher with MIT License 4 votes vote down vote up
public List<HttpFiltersSource> getFilterFactories() {
    return filterFactories;
}
 
Example #20
Source File: BrowserUpProxyServer.java    From browserup-proxy with Apache License 2.0 4 votes vote down vote up
@Override
public void addFirstHttpFilterFactory(HttpFiltersSource filterFactory) {
    filterFactories.add(0, filterFactory);
}
 
Example #21
Source File: BrowserMobProxyServer.java    From AndroidHttpCapture with MIT License 4 votes vote down vote up
@Override
public void addFirstHttpFilterFactory(HttpFiltersSource filterFactory) {
    filterFactories.add(0, filterFactory);
}
 
Example #22
Source File: BrowserMobProxyServer.java    From AndroidHttpCapture with MIT License 4 votes vote down vote up
@Override
public void addLastHttpFilterFactory(HttpFiltersSource filterFactory) {
    filterFactories.add(filterFactory);
}
 
Example #23
Source File: BrowserMobProxyServer.java    From AndroidHttpCapture with MIT License 4 votes vote down vote up
public void addHttpFilterFactory(HttpFiltersSource filterFactory) {
    filterFactories.add(filterFactory);
}
 
Example #24
Source File: BrowserMobProxyServer.java    From AndroidHttpCapture with MIT License 4 votes vote down vote up
public List<HttpFiltersSource> getFilterFactories() {
    return filterFactories;
}
 
Example #25
Source File: BrowserMobProxyServer.java    From CapturePacket with MIT License 4 votes vote down vote up
public void addHttpFilterFactory(HttpFiltersSource filterFactory) {
    filterFactories.add(filterFactory);
}
 
Example #26
Source File: BrowserUpProxyServer.java    From browserup-proxy with Apache License 2.0 4 votes vote down vote up
public List<HttpFiltersSource> getFilterFactories() {
    return filterFactories;
}
 
Example #27
Source File: BrowserMobProxyServer.java    From CapturePacket with MIT License 4 votes vote down vote up
@Override
public void addFirstHttpFilterFactory(HttpFiltersSource filterFactory) {
    filterFactories.add(0, filterFactory);
}
 
Example #28
Source File: BrowserMobProxyServer.java    From CapturePacket with MIT License 4 votes vote down vote up
@Override
public void addLastHttpFilterFactory(HttpFiltersSource filterFactory) {
    filterFactories.add(filterFactory);
}
 
Example #29
Source File: BrowserUpProxyServer.java    From browserup-proxy with Apache License 2.0 4 votes vote down vote up
public void addHttpFilterFactory(HttpFiltersSource filterFactory) {
    filterFactories.add(filterFactory);
}
 
Example #30
Source File: BrowserMobProxyServer.java    From CapturePacket with MIT License 4 votes vote down vote up
public List<HttpFiltersSource> getFilterFactories() {
    return filterFactories;
}