chiark / gitweb /
hippotatlib/__init__.py: Make `vaddr' be an actual address object.
[hippotat.git] / hippotat
index 8bcd62f89ec57fece063106c8a4d9238927fc791..7130f9154b870a9c23e84cf579a1059aa767cf9c 100755 (executable)
--- 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,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')
@@ -58,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:
@@ -79,7 +88,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 +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"