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
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
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))
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
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