Ticket #150: 150-http-proxy.patch

File 150-http-proxy.patch, 3.0 KB (added by duck, 13 years ago)

HTTP proxy support in Negotiate v2

  • foolscap/negotiate.py

    diff --git foolscap/negotiate.py foolscap/negotiate.py
    index f74daba..ac8e9cb 100644
    class Negotiation(protocol.Protocol): 
    329329        # we are using an encrypted Tub is separate, and expressed in our
    330330        # Hello block.
    331331        req = []
     332        proxyPrefix = ''
     333        if 'http-proxy' in self.tub.options:
     334            proxyPrefix = 'http://' + self.targetHost
     335            self.log("sendPlaintextClient: using HTTP Proxy %s"
     336                % self.tub.options['http-proxy'])
    332337        if self.target.encrypted:
    333338            self.log("sendPlaintextClient: GET for tubID %s" %
    334339                     self.target.tubID)
    335             req.append("GET /id/%s HTTP/1.1" % self.target.tubID)
     340            req.append("GET %s/id/%s HTTP/1.1" % (proxyPrefix, self.target.tubID))
    336341        else:
    337342            self.log("sendPlaintextClient: GET for no tubID")
    338             req.append("GET /id/ HTTP/1.1")
     343            req.append("GET %s/id/ HTTP/1.1" % proxyPrefix)
    339344        req.append("Host: %s" % self.targetHost)
    340345        self.log("sendPlaintextClient: wantEncryption=%s" % self.wantEncryption)
    341346        if self.wantEncryption:
    class TubConnector(object): 
    13531358            if location in self.attemptedLocations:
    13541359                continue
    13551360            self.attemptedLocations.append(location)
    1356             host, port = location
     1361            if 'http-proxy' in self.tub.options:
     1362                host, port = self.tub.options['http-proxy'].split(':')
     1363                destination = location[0]
     1364            else:
     1365                host, port = location
     1366                destination = host
    13571367            lp = self.log("connectTCP to %s" % (location,))
    1358             f = TubConnectorClientFactory(self, host, lp)
    1359             c = reactor.connectTCP(host, port, f)
     1368            f = TubConnectorClientFactory(self, destination, lp)
     1369            c = reactor.connectTCP(host, int(port), f)
    13601370            self.pendingConnections[f] = c
    13611371            # the tcp.Connector that we get back from reactor.connectTCP will
    13621372            # retain a reference to the transport that it creates, so we can
  • foolscap/pb.py

    diff --git foolscap/pb.py foolscap/pb.py
    index 83a3e06..d742ff4 100644
    class Tub(service.MultiService): 
    205205                    connection negotiation. Currently defined keys are:
    206206                     - debug_slow: if True, wait half a second between
    207207                                   each negotiation response
     208                     - http-proxy: if set, connect using this HTTP proxy
    208209
    209210    @ivar brokers: maps TubIDs to L{Broker} instances
    210211
    class Tub(service.MultiService): 
    359360            self.setLogGathererFURL(value)
    360361        elif name == "log-gatherer-furlfile":
    361362            self.setLogGathererFURLFile(value)
     363        elif name == "http-proxy":
     364            self.options['http-proxy'] = value
    362365        elif name == "bridge-twisted-logs":
    363366            assert value is not False, "cannot unbridge twisted logs"
    364367            if value is True: