Rev 5959: Allows HEAD to be used in tests while still requiring authentication. in file:///home/vila/src/bzr/bugs/723074-http-debug-mask-credentials/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Jun 7 11:11:08 UTC 2011


At file:///home/vila/src/bzr/bugs/723074-http-debug-mask-credentials/

------------------------------------------------------------
revno: 5959
revision-id: v.ladeuil+lp at free.fr-20110607111108-bt0ud8l7vrxlgib6
parent: v.ladeuil+lp at free.fr-20110607081232-yvtbewkbc6no8wsq
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 723074-http-debug-mask-credentials
timestamp: Tue 2011-06-07 13:11:08 +0200
message:
  Allows HEAD to be used in tests while still requiring authentication.
-------------- next part --------------
=== modified file 'bzrlib/tests/http_utils.py'
--- a/bzrlib/tests/http_utils.py	2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/http_utils.py	2011-06-07 11:11:08 +0000
@@ -284,21 +284,30 @@
     # - auth_header_recv: the header received containing auth
     # - auth_error_code: the error code to indicate auth required
 
+    def _require_authentication(self):
+        # Note that we must update test_case_server *before*
+        # sending the error or the client may try to read it
+        # before we have sent the whole error back.
+        tcs = self.server.test_case_server
+        tcs.auth_required_errors += 1
+        self.send_response(tcs.auth_error_code)
+        self.send_header_auth_reqed()
+        # We do not send a body
+        self.send_header('Content-Length', '0')
+        self.end_headers()
+        return
+
     def do_GET(self):
         if self.authorized():
             return http_server.TestingHTTPRequestHandler.do_GET(self)
         else:
-            # Note that we must update test_case_server *before*
-            # sending the error or the client may try to read it
-            # before we have sent the whole error back.
-            tcs = self.server.test_case_server
-            tcs.auth_required_errors += 1
-            self.send_response(tcs.auth_error_code)
-            self.send_header_auth_reqed()
-            # We do not send a body
-            self.send_header('Content-Length', '0')
-            self.end_headers()
-            return
+            return self._require_authentication()
+
+    def do_HEAD(self):
+        if self.authorized():
+            return http_server.TestingHTTPRequestHandler.do_HEAD(self)
+        else:
+            return self._require_authentication()
 
 
 class BasicAuthRequestHandler(AuthRequestHandler):



More information about the bazaar-commits mailing list