-# we do NOT use the built-in timeOut mixin as it's very very buggy!
-class TimeoutHTTPChannel(http.HTTPChannel):
- timeout = config.HTTP_REQUEST_TIMEOUT
-
- def connectionMade(self):
- self.customTimeout = reactor.callLater(self.timeout, self.timeoutOccured)
- http.HTTPChannel.connectionMade(self)
-
- def timeoutOccured(self):
- self.customTimeout = None
- self.transport.loseConnection()
-
- def cancelTimeout(self):
- if self.customTimeout is not None:
- try:
- self.customTimeout.cancel()
- self.customTimeout = None
- except error.AlreadyCalled:
- pass
-
- def connectionLost(self, reason):
- self.cancelTimeout()
- http.HTTPChannel.connectionLost(self, reason)
-