X-Git-Url: https://git.distorted.org.uk/~mdw/hippotat/blobdiff_plain/d41617043a477168c2460e00e6099528219c7163..916021af0447d61202fd909a722c28b08a4a13a3:/hippotat diff --git a/hippotat b/hippotat index abe1cae..7130f91 100755 --- a/hippotat +++ b/hippotat @@ -42,6 +42,14 @@ class GeneralResponseConsumer(twisted.internet.protocol.Protocol): def connectionMade(self): self._log(DBG.HTTP_CTRL, 'connectionMade') + def connectionLostOK(self, reason): + return (reason.check(twisted.web.client.ResponseDone) or + reason.check(twisted.web.client.PotentialDataLoss)) + # twisted.web.client.PotentialDataLoss is an entirely daft + # exception. It will occur every time if the origin server does + # not provide a Content-Length. (hippotatd does, of course, but + # the HTTP transaction might be proxied.) + class ResponseConsumer(GeneralResponseConsumer): def __init__(self, cl, req, resp): super().__init__(cl, req, resp, 'RC') @@ -59,7 +67,7 @@ class ResponseConsumer(GeneralResponseConsumer): def connectionLost(self, reason): reason_msg = 'connectionLost ' + str(reason) self._log(DBG.HTTP_CTRL, reason_msg) - if not reason.check(twisted.web.client.ResponseDone): + if not self.connectionLostOK(reason): self._latefailure(reason_msg) return try: @@ -96,7 +104,7 @@ class ErrorResponseConsumer(GeneralResponseConsumer): mbody = self._m.decode('utf-8') except Exception: mbody = repr(self._m) - if not reason.check(twisted.web.client.ResponseDone): + if not self.connectionLostOK(reason): mbody += ' || ' + str(reason) self._cl.req_err(self._req, "FAILED %d %s | %s"