Ticket #4891: limit_HTTP_requests_and_added_tests.patch

File limit_HTTP_requests_and_added_tests.patch, 2.2 KB (added by Indradhanush Gupta, 6 years ago)

Made a small change, _pauseFlag = False once the resumeProducing() is about to be called.

  • twisted/web/http.py

     
    585585    content = None
    586586    _forceSSL = 0
    587587    _disconnected = False
     588    _queuedRequests = 0 # number of total pipelined requests currently in queue
     589    _maxQueuedRequests = 8
     590    _pauseFlag = False
    588591
    589592    def __init__(self, channel, queued):
    590593        """
     
    600603        self.responseHeaders = Headers()
    601604        self.cookies = [] # outgoing cookies
    602605
     606        if self._pauseFlag and self._queuedRequests < self._maxQueuedRequests:
     607                        _pauseFlag = False           
     608                        producer.resumeProducing()         
     609        if not self._pauseFlag and self._queuedRequests >= self._maxQueuedRequests:
     610                        _pauseFlag = True           
     611                        producer.pauseProducing()
     612           
     613
    603614        if queued:
     615            self._queuedRequests += 1
    604616            self.transport = StringTransport()
    605617        else:
    606618            self.transport = self.channel.transport
     
    634646        """
    635647        Called when have finished responding and are no longer queued.
    636648        """
     649        if self._queuedRequests > 0:
     650            self._queuedRequests -= 1
    637651        if self.producer:
    638652            log.err(RuntimeError("Producer was not unregistered for %s" % self.uri))
    639653            self.unregisterProducer()
  • twisted/web/test/test_http.py

     
    16981698            '<Otherwise at 0x%x method=(no method yet) uri=(no uri yet) '
    16991699            'clientproto=(no clientproto yet)>' % (id(request),))
    17001700
     1701        def test_maxQueuedRequests(self):
     1702                """
     1703                Creates 9 pipelined requests to check whether requests are limited to 8
     1704                """
     1705                channel = DummyChannel()
     1706                req = [http.Request(channel, True) for i in xrange(8)]
     1707                self.assertTrue(Request._pauseFlag == False)   
     1708                req[0].noLongerQueued()
     1709                req[1].noLongerQueued()
     1710                self.assertTrue(Request._pauseFlag == False)
    17011711
    17021712
     1713
    17031714class MultilineHeadersTestCase(unittest.TestCase):
    17041715    """
    17051716    Tests to exercise handling of multiline headers by L{HTTPClient}.  RFCs 1945