hgweb: store and use request method on parsed request
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 10 Mar 2018 10:44:56 -0800
changeset 36848 16292bbda39c
parent 36847 ed0456fde625
child 36849 0bc771bba220
hgweb: store and use request method on parsed request PEP 3333 says that REQUEST_METHOD is always defined. Differential Revision: https://phab.mercurial-scm.org/D2745
mercurial/hgweb/request.py
mercurial/wireprotoserver.py
--- a/mercurial/hgweb/request.py	Sat Mar 10 10:45:12 2018 -0800
+++ b/mercurial/hgweb/request.py	Sat Mar 10 10:44:56 2018 -0800
@@ -63,6 +63,8 @@
 class parsedrequest(object):
     """Represents a parsed WSGI request / static HTTP request parameters."""
 
+    # Request method.
+    method = attr.ib()
     # Full URL for this request.
     url = attr.ib()
     # URL without any path components. Just <proto>://<host><port>.
@@ -207,7 +209,8 @@
     if 'CONTENT_LENGTH' in env and 'HTTP_CONTENT_LENGTH' not in env:
         headers['Content-Length'] = env['CONTENT_LENGTH']
 
-    return parsedrequest(url=fullurl, baseurl=baseurl,
+    return parsedrequest(method=env['REQUEST_METHOD'],
+                         url=fullurl, baseurl=baseurl,
                          advertisedurl=advertisedfullurl,
                          advertisedbaseurl=advertisedbaseurl,
                          apppath=apppath,
--- a/mercurial/wireprotoserver.py	Sat Mar 10 10:45:12 2018 -0800
+++ b/mercurial/wireprotoserver.py	Sat Mar 10 10:44:56 2018 -0800
@@ -324,7 +324,7 @@
     # the HTTP response. In other words, it helps prevent deadlocks
     # on clients using httplib.
 
-    if (wsgireq.env[r'REQUEST_METHOD'] == r'POST' and
+    if (req.method == 'POST' and
         # But not if Expect: 100-continue is being used.
         (req.headers.get('Expect', '').lower() != '100-continue')):
         wsgireq.drain()