chiark / gitweb /
ResponseConsumer: break out connectionLostOK into superclass
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 22 Aug 2017 16:37:06 +0000 (17:37 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 22 Aug 2017 16:37:06 +0000 (17:37 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
hippotat

index abe1cae..200cf3a 100755 (executable)
--- a/hippotat
+++ b/hippotat
@@ -42,6 +42,9 @@ class GeneralResponseConsumer(twisted.internet.protocol.Protocol):
   def connectionMade(self):
     self._log(DBG.HTTP_CTRL, 'connectionMade')
 
   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')
 class ResponseConsumer(GeneralResponseConsumer):
   def __init__(self, cl, req, resp):
     super().__init__(cl, req, resp, 'RC')
@@ -59,7 +62,7 @@ class ResponseConsumer(GeneralResponseConsumer):
   def connectionLost(self, reason):
     reason_msg = 'connectionLost ' + str(reason)
     self._log(DBG.HTTP_CTRL, reason_msg)
   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:
       self._latefailure(reason_msg)
       return
     try:
@@ -96,7 +99,7 @@ class ErrorResponseConsumer(GeneralResponseConsumer):
       mbody = self._m.decode('utf-8')
     except Exception:
       mbody = repr(self._m)
       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"
       mbody += ' || ' + str(reason)
     self._cl.req_err(self._req,
             "FAILED %d %s | %s"