[PATCH 2 of 2] hgweb: respond 403 forbidden for ssl required error

Yuya Nishihara yuya at tcha.org
Wed Sep 5 10:29:51 CDT 2012


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1346857167 -32400
# Branch stable
# Node ID d66f635d24550dd2df08085f6ec171dc0953575b
# Parent  c5df3b232f38cbd260a3f5fcd610d5b94502b758
hgweb: respond 403 forbidden for ssl required error

It's preferable to report "ssl required" as an error, so that the client
can detect error and exit with 255. Currently hg exits with 1, which is
"nothing to push."

diff --git a/mercurial/hgweb/common.py b/mercurial/hgweb/common.py
--- a/mercurial/hgweb/common.py
+++ b/mercurial/hgweb/common.py
@@ -48,7 +48,7 @@ def checkauthz(hgweb, req, op):
     # and replayed
     scheme = req.env.get('wsgi.url_scheme')
     if hgweb.configbool('web', 'push_ssl', True) and scheme != 'https':
-        raise ErrorResponse(HTTP_OK, 'ssl required')
+        raise ErrorResponse(HTTP_FORBIDDEN, 'ssl required')
 
     deny = hgweb.configlist('web', 'deny_push')
     if deny and (not user or deny == ['*'] or user in deny):
diff --git a/tests/test-push-http.t b/tests/test-push-http.t
--- a/tests/test-push-http.t
+++ b/tests/test-push-http.t
@@ -29,11 +29,9 @@ expect ssl error
   $ req
   pushing to http://localhost:$HGPORT/
   searching for changes
-  remote: ssl required
-  remote: ssl required
-  updating cb9a9f314b8b to public failed!
+  abort: HTTP Error 403: ssl required
   % serve errors
-  [1]
+  [255]
 
 expect authorization error
 


More information about the Mercurial-devel mailing list