Ticket #6768: 6768-fixes-v2.patch

File 6768-fixes-v2.patch, 2.4 KB (added by Andy Lutomirski, 7 years ago)

Replacement patch (against the branch, r40179)

  • twisted/web/proxy.py

    diff --git twisted/web/proxy.py twisted/web/proxy.py
    index 378cdd0..2a56b96 100644
    class ProxyClient(HTTPClient): 
    4949        headers.pop('keep-alive', None)
    5050        self.headers = headers
    5151        self.data = data
    52         father.notifyFinish().addErrback(self.fatherFailed)
    5352
    5453
    5554    def connectionMade(self):
     55        self.father.notifyFinish().addErrback(self._fatherFailed)
    5656        self.sendCommand(self.command, self.rest)
    5757        for header, value in self.headers.items():
    5858            self.sendHeader(header, value)
    class ProxyClient(HTTPClient): 
    9090            self.transport.loseConnection()
    9191
    9292
    93     def fatherFailed(self, failure):
    94         if not self._finished:
    95             self.transport.loseConnection()
    96             self._finished = True
     93    def _fatherFailed(self, failure):
     94        """
     95        This is called when the proxy's client disconnects or otherwise aborts.
     96        We want to abort, too, so that we don't tie up resources on the
     97        server we're connecting to.
     98        """
     99        self._finished = True
     100        self.transport.loseConnection()
    97101
    98102
    99103
  • twisted/web/test/test_proxy.py

    diff --git twisted/web/test/test_proxy.py twisted/web/test/test_proxy.py
    index edc7ae7..d67244c 100644
    class ProxyClientTestCase(TestCase): 
    375375        self.assertForwardsResponse(
    376376            request, 200, 'OK', headers.items(), '')
    377377
     378
    378379    def test_parentDisconnected(self):
    379380        """
    380         Check that the client disconnects if the parent request is dropped.
     381        The client should disconnect if the parent request is dropped.
    381382        """
    382383        request = self.makeRequest('foo')
    383384        client = self.makeProxyClient(request, headers={"accept": "text/html"})
    class ProxyClientTestCase(TestCase): 
    391392        self.assertFalse(client.transport.connected)
    392393
    393394
     395    def test_parentDisconnectedEarly(self):
     396        """
     397        The proxy should survive a parent disconnection before the client
     398        connects.
     399        """
     400        request = self.makeRequest('foo')
     401        client = self.makeProxyClient(request, headers={"accept": "text/html"})
     402        request.processingFailed(main.CONNECTION_LOST)
     403
     404        # Note: this test is a little bit odd.  We're testing that the
     405        # processingFailed call doesn't raise an exception.
     406
     407
    394408
    395409class ProxyClientFactoryTestCase(TestCase):
    396410    """