如何设置代理代理超时



客户端。代理类具有连接超时参数:

agent = client.Agent(reactor, connectTimeout=timeout, pool=pool)

使用客户端时如何设置此超时。代理代理?

auth = base64.b64encode("%s:%s" % (username, password))
headers['Proxy-Authorization'] = ["Basic " + auth.strip()]
endpoint = endpoints.TCP4ClientEndpoint(reactor, host, port)
agent = client.ProxyAgent(endpoint, reactor=reactor, pool=pool)

传递给ProxyAgentTCP4ClientEndpoint可以通过超时进行初始化。

auth = base64.b64encode("%s:%s" % (username, password))
headers['Proxy-Authorization'] = ["Basic " + auth.strip()]
endpoint = endpoints.TCP4ClientEndpoint(reactor, host, port, timeout=yourTimeout)
agent = client.ProxyAgent(endpoint, reactor=reactor, pool=pool)

这假设您要设置连接到代理的超时。 如果要设置代理用于连接到上游 HTTP 服务器的超时,则无法控制这一点。

它看起来像客户端。代理代理没有连接超时属性:

class ProxyAgent(_AgentBase):
    """
    An HTTP agent able to cross HTTP proxies.
    @ivar _proxyEndpoint: The endpoint used to connect to the proxy.
    @since: 11.1
    """
    def __init__(self, endpoint, reactor=None, pool=None):
        if reactor is None:
            from twisted.internet import reactor
        _AgentBase.__init__(self, reactor, pool)
        self._proxyEndpoint = endpoint

    def request(self, method, uri, headers=None, bodyProducer=None):
        """
        Issue a new request via the configured proxy.
        """
        # Cache *all* connections under the same key, since we are only
        # connecting to a single destination, the proxy:
        key = ("http-proxy", self._proxyEndpoint)
        # To support proxying HTTPS via CONNECT, we will use key
        # ("http-proxy-CONNECT", scheme, host, port), and an endpoint that
        # wraps _proxyEndpoint with an additional callback to do the CONNECT.
        return self._requestWithEndpoint(key, self._proxyEndpoint, method,
                                         _URI.fromBytes(uri), headers,
                                         bodyProducer, uri)

ProxyAgent继承自Agent相同的类(_AgentBase),而不是从Agent本身继承。

最新更新