Example #1
0
    def __init__(self, url):
        """
        Initialises a new Client object


        :param url: This is where the BrowserMob Proxy lives
        """
        self.host = "http://" + url
        resp = request_1.post("%s/proxy" % self.host, {})  #  urlencode('')
        jcontent = json.loads(resp.content)
        self.port = jcontent["port"]
        url_parts = self.host.split(":")
        self.proxy = url_parts[1][2:] + ":" + str(self.port)
Example #2
0
    def request_interceptor(self, js):
        """
        Executes the javascript against each request


        :param js: the javascript to execute
        """
        r = request_1.post(
            url="%s/proxy/%s/interceptor/request" % (self.host, self.port),
            data=js,
            headers={"content-type": "x-www-form-urlencoded"},
        )
        return r.status_code
Example #3
0
    def remap_hosts(self, address, ip_address):
        """
        Remap the hosts for a specific URL


        :param address: url that you wish to remap
        :param ip_address: IP Address that will handle all traffic for the address passed in
        """
        assert address is not None and ip_address is not None
        r = request_1.post(
            "%s/proxy/%s/hosts" % (self.host, self.port),
            json.dumps({address: ip_address}),
            headers={"content-type": "application/json"},
        )
        return r.status_code
Example #4
0
    def basic_authentication(self, domain, username, password):
        """
        This add automatic basic authentication


        :param domain: domain to set authentication credentials for
        :param username: valid username to use when authenticating
        :param  password: valid password to use when authenticating
        """
        r = request_1.post(
            url="%s/proxy/%s/auth/basic/%s" % (self.host, self.port, domain),
            data=json.dumps({"username": username, "password": password}),
            headers={"content-type": "application/json"},
        )
        return r.status_code
Example #5
0
    def headers(self, headers):
        """
        This sets the headers that will set by the proxy on all requests


        :param headers: this is a dictionary of the headers to be set
        """
        if not isinstance(headers, dict):
            raise TypeError("headers needs to be dictionary")

        r = request_1.post(
            url="%s/proxy/%s/headers" % (self.host, self.port),
            data=json.dumps(headers),
            headers={"content-type": "application/json"},
        )
        return r.status_code