X-Git-Url: https://git.distorted.org.uk/~mdw/hippotat/blobdiff_plain/dbf9b0e5479e842dfeb0ad4e552a0570ff4ea342..216519e342072164533ae340141d585c638db8e2:/hippotat diff --git a/hippotat b/hippotat index 8bcd62f..200cf3a 100755 --- a/hippotat +++ b/hippotat @@ -33,6 +33,7 @@ class GeneralResponseConsumer(twisted.internet.protocol.Protocol): def __init__(self, cl, req, resp, desc): self._cl = cl self._req = req + self._resp = resp self._desc = desc def _log(self, dflag, msg, **kwargs): @@ -41,6 +42,9 @@ 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) + class ResponseConsumer(GeneralResponseConsumer): def __init__(self, cl, req, resp): super().__init__(cl, req, resp, 'RC') @@ -58,7 +62,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: @@ -79,7 +83,6 @@ class ResponseConsumer(GeneralResponseConsumer): class ErrorResponseConsumer(GeneralResponseConsumer): def __init__(self, cl, req, resp): super().__init__(cl, req, resp, 'ERROR-RC') - self._resp = resp self._m = b'' try: self._phrase = resp.phrase.decode('utf-8') @@ -96,7 +99,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"