Ejemplo n.º 1
0
    def build_agent(self, proxy, headers):
        """Build an agent for this request
        """
        fragments = common.parse_proxy(proxy)
        pool = self.build_pool()
        if fragments.host:
            # add proxy authentication header
            auth = base64.b64encode("%s:%s" %
                                    (fragments.username, fragments.password))
            headers['Proxy-Authorization'] = ["Basic " + auth.strip()]
            # generate the agent
            endpoint = endpoints.TCP4ClientEndpoint(
                reactor,
                fragments.host,
                int(fragments.port),
                timeout=self.settings.timeout)
            agent = client.ProxyAgent(endpoint, reactor=reactor, pool=pool)
        else:
            agent = client.Agent(reactor,
                                 connectTimeout=self.settings.timeout,
                                 pool=pool)

        agent = client.ContentDecoderAgent(agent,
                                           [('gzip', client.GzipDecoder)])
        # XXX if use same cookie for all then works...
        # cookies usually empty
        if proxy in self.cookiejars:
            cj = self.cookiejars[proxy]
        else:
            cj = cookielib.CookieJar()
            self.cookiejars[proxy] = cj
        agent = client.CookieAgent(agent, cj)
        return agent
Ejemplo n.º 2
0
 def setProxy(self, proxy):
     """Allow setting string as proxy
     """
     fragments = common.parse_proxy(proxy)
     if fragments.host:
         QNetworkAccessManager.setProxy(self, 
             QNetworkProxy(QNetworkProxy.HttpProxy, 
               fragments.host, int(fragments.port), 
               fragments.username, fragments.password
             )
         )
     else:
         common.logger.info('Invalid proxy:' + proxy)
         proxy = None
Ejemplo n.º 3
0
 def setProxy(self, proxy):
     """Parse proxy components from proxy
     """
     if proxy:
         fragments = common.parse_proxy(proxy)
         if fragments['host']:
             QNetworkAccessManager.setProxy(
                 self,
                 QNetworkProxy(QNetworkProxy.HttpProxy, fragments['host'],
                               int(fragments['port']),
                               fragments['username'],
                               fragments['password']))
         else:
             common.logger.info('Invalid proxy: ' + str(proxy))
Ejemplo n.º 4
0
 def setProxy(self, proxy):
     """Allow setting string as proxy
     """
     if proxy:
         fragments = common.parse_proxy(proxy)
         if fragments.host:
             QNetworkAccessManager.setProxy(self, 
                 QNetworkProxy(QNetworkProxy.HttpProxy, 
                   fragments.host, int(fragments.port), 
                   fragments.username, fragments.password
                 )
             )
         else:
             common.logger.info('Invalid proxy: ' + str(proxy))
             proxy = None
Ejemplo n.º 5
0
    def build_agent(self, proxy, headers):
        """Build an agent for this request
        """
        fragments = common.parse_proxy(proxy)
        pool = self.build_pool()
        if fragments.host:
            # add proxy authentication header
            auth = base64.b64encode("%s:%s" % (fragments.username, fragments.password))
            headers['Proxy-Authorization'] = ["Basic " + auth.strip()]
            # generate the agent
            endpoint = endpoints.TCP4ClientEndpoint(reactor, fragments.host, int(fragments.port))
            agent = client.ProxyAgent(endpoint, reactor=reactor, pool=pool)
        else:
            agent = client.Agent(reactor, connectTimeout=self.settings.timeout, pool=pool)

        agent = client.ContentDecoderAgent(agent, [('gzip', client.GzipDecoder)])
        #agent = client.RedirectAgent(agent, self.settings.num_redirects)
        #cookieJar = cookielib.CookieJar()
        #agent = CookieAgent(agent, cookieJar)
        return agent