From bcbb51fe4aee8428ed1f8c2b1e0ec9c2768dfd3b Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@allmydata.com>
Date: Tue, 12 Aug 2008 19:45:20 -0700
Subject: [PATCH] test_web: workaround broken HEAD behavior in twisted-2.5.0
 and earlier

---
 src/allmydata/test/test_web.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py
index 9173c553..eed62d1e 100644
--- a/src/allmydata/test/test_web.py
+++ b/src/allmydata/test/test_web.py
@@ -99,6 +99,18 @@ class HTTPClientHEADFactory(client.HTTPClientFactory):
         client.HTTPClientFactory.__init__(self, *args, **kwargs)
         self.deferred.addCallback(lambda res: self.response_headers)
 
+    def noPage(self, reason):
+        # Twisted-2.5.0 and earlier had a bug, in which they would raise an
+        # exception when the response to a HEAD request had no body (when in
+        # fact they are defined to never have a body). This was fixed in
+        # Twisted-8.0 . To work around this, we catch the
+        # PartialDownloadError and make it disappear.
+        if (reason.check(client.PartialDownloadError)
+            and self.method.upper() == "HEAD"):
+            self.page("")
+            return
+        return client.HTTPClientFactory.noPage(self, reason)
+
 
 class WebMixin(object):
     def setUp(self):
-- 
2.45.2