Ticket #3207: http.py.patch

File http.py.patch, 2.5 KB (added by camrdale, 8 years ago)

patch to fix web2/client/http.py

  • web2/client/http.py

    old new  
    2626    Exception raised when a HTTP error happened.
    2727    """
    2828
     29class PipelineError(Exception):
     30    """
     31    Exception raised when a HTTP error happened.
     32    """
     33
    2934
    3035
    3136class ClientRequest(object):
     
    8287        self.closeAfter = closeAfter
    8388        self.transport = self.channel.transport
    8489        self.responseDefer = Deferred()
     90        self.started = False
    8591
    8692    def submit(self):
    8793        l = []
     
    152158        the C{responseDefer} if no response has been sent yet, or close the
    153159        stream.
    154160        """
    155         self.abortParse()
     161        if self.started:
     162            self.abortParse()
    156163        if hasattr(self, 'stream') and self.stream is not None:
    157164            self.stream.finish(err)
    158165        else:
     
    168175        self._error(reason)
    169176
    170177    def gotInitialLine(self, initialLine):
     178        self.started = True
    171179        parts = initialLine.split(' ', 2)
    172180
    173181        # Parse the initial request line
     
    346354                self.transport.loseConnection()
    347355
    348356    def setReadPersistent(self, persist):
     357        oldPersist = self.readPersistent
    349358        self.readPersistent = persist
    350359        if not persist:
    351360            # Tell all requests but first to abort.
    352             for request in self.inRequests[1:]:
    353                 request.connectionLost(None)
     361            lostRequests = self.inRequests[1:]
    354362            del self.inRequests[1:]
     363            for request in lostRequests:
     364                request.connectionLost(PipelineError('Pipelined connection was closed.'))
     365        elif (oldPersist is PERSIST_NO_PIPELINE and
     366              persist is PERSIST_PIPELINE and
     367              self.outRequest is None):
     368            self.manager.clientPipelining(self)
    355369
    356370    def connectionLost(self, reason):
    357371        self.readPersistent = False
    358372        self.setTimeout(None)
    359373        self.manager.clientGone(self)
    360         # Tell all requests to abort.
    361         for request in self.inRequests:
     374        # Cancel the current request
     375        if self.inRequests and self.inRequests[0] is not None:
     376            self.inRequests[0].connectionLost(reason)
     377        # Tell all remaining requests to abort.
     378        lostRequests = self.inRequests[1:]
     379        del self.inRequests[1:]
     380        for request in lostRequests:
    362381            if request is not None:
    363                 request.connectionLost(reason)
     382                request.connectionLost(PipelineError('Pipelined connection was closed.'))
    364383