Ticket #6768: proxy_cr_fixes.patch

File proxy_cr_fixes.patch, 3.3 KB (added by Andy Lutomirski, 7 years ago)

response to comment 5

  • twisted/web/proxy.py

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

     
    375375        self.assertForwardsResponse(
    376376            request, 200, 'OK', headers.items(), '')
    377377
     378
    378379    def test_parentDisconnected(self):
    379380        """
    380381        Check that the client disconnects if the parent request is dropped.
     
    391392        self.assertFalse(client.transport.connected)
    392393
    393394
     395    def test_parentDisconnectedEarly(self):
     396        """
     397        Check that the proxy survives 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)
    394403
     404
     405    def test_parentDisconnectedLate(self):
     406        """
     407        Check that the proxy survives a parent disconnection after the request
     408        is done.
     409        """
     410        request = self.makeRequest('foo')
     411        client = self.makeProxyClient(request, headers={"accept": "text/html"})
     412        self.connectProxy(client)
     413        headers = {
     414            'Server': ['bar'],
     415            'Date': ['2010-01-01'],
     416            'Content-Type': ['application/x-baz'],
     417            }
     418        client.dataReceived(
     419            self.makeResponseBytes(200, "OK", headers.items(), ''))
     420        self.assertForwardsResponse(
     421            request, 200, 'OK', headers.items(), '')
     422
     423        client.transport.loseConnection()
     424        request.processingFailed(main.CONNECTION_LOST)
     425
     426
     427
    395428class ProxyClientFactoryTestCase(TestCase):
    396429    """
    397430    Tests for L{ProxyClientFactory}.
  • twisted/web/topfiles/6768.feature

     
     1twisted.web.proxy.ProxyClient (and all of its users in twisted.web.proxy) will now close HTTP connections that they initiate if the incoming connection to the proxy dies before receiving a response.
     2 No newline at end of file