All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mike10004.seleniumhelp.BasicBmpConfigurator Maven / Gradle / Ivy

There is a newer version: 0.58
Show newest version
package com.github.mike10004.seleniumhelp;

import com.google.common.base.MoreObjects;
import com.browserup.bup.BrowserUpProxy;
import com.browserup.bup.BrowserUpProxyServer;
import com.browserup.bup.mitm.CertificateAndKeySource;
import org.littleshoot.proxy.ChainedProxyManager;

import javax.annotation.Nullable;

import static java.util.Objects.requireNonNull;

class BasicBmpConfigurator implements BmpConfigurator {

    private final UpstreamProxyDefinition upstreamProxyDefinition;

    public BasicBmpConfigurator(UpstreamProxyDefinition upstreamProxyDefinition) {
        this.upstreamProxyDefinition = requireNonNull(upstreamProxyDefinition, "upstreamProxyDefinition");
    }

    @Override
    public void configureUpstream(BrowserUpProxy bmp) {
        if (upstreamProxyDefinition == null) {
            bmp.setChainedProxy(null);
            if (bmp instanceof BrowserUpProxyServer) {
                ((BrowserUpProxyServer) bmp).setChainedProxyManager(null);
            }
        } else {
            ChainedProxyManager chainedProxyManager = upstreamProxyDefinition.createUpstreamProxy();
            ((BrowserUpProxyServer)bmp).setChainedProxyManager(chainedProxyManager);
        }
    }

    @Override
    public WebdrivingConfig createWebdrivingConfig(BrowserUpProxy bmp, @Nullable CertificateAndKeySource certificateAndKeySource) {
        WebdrivingProxyDefinition proxy = ProxyDefinitionBuilder.through(BrowserMobs.resolveSocketAddress(bmp))
                .buildWebdrivingProxyDefinition();
        return WebdrivingConfig.builder()
                .proxy(proxy)
                .certificateAndKeySource(certificateAndKeySource)
                .build();
    }

    @Override
    public String toString() {
        MoreObjects.ToStringHelper h = MoreObjects.toStringHelper(this);
        h.add("upstreamProxyDefinition", upstreamProxyDefinition);
        return h.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy