cgi.py: Export request method from `cgiparse'.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 13 Jul 2013 15:34:40 +0000 (16:34 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 6 Apr 2014 10:54:33 +0000 (11:54 +0100)
We'll want to know it later.

cgi.py

diff --git a/cgi.py b/cgi.py
index d66bfc6..1aa2917 100644 (file)
--- a/cgi.py
+++ b/cgi.py
@@ -311,6 +311,7 @@ def cgi_errors(hook = None):
 ### CGI input.
 
 ## Lots of global variables to be filled in by `cgiparse'.
+METHOD = None
 COOKIE = {}
 SPECIAL = {}
 PARAM = []
@@ -377,20 +378,20 @@ def cgiparse():
         True if the client connection is carried over SSL or TLS.
   """
 
-  global SSLP
+  global METHOD, SSLP
 
   def getenv(var):
     try: return ENV[var]
     except KeyError: raise U.ExpectedError, (500, "No `%s' supplied" % var)
 
   ## Yes, we want the request method.
-  method = getenv('REQUEST_METHOD')
+  METHOD = getenv('REQUEST_METHOD')
 
   ## Acquire the query string.
-  if method == 'GET':
+  if METHOD == 'GET':
     q = getenv('QUERY_STRING')
 
-  elif method == 'POST':
+  elif METHOD == 'POST':
 
     ## We must read the query string from stdin.
     n = getenv('CONTENT_LENGTH')
@@ -404,7 +405,7 @@ def cgiparse():
       raise U.ExpectedError, (500, "Failed to read correct length")
 
   else:
-    raise U.ExpectedError, (500, "Unexpected request method `%s'" % method)
+    raise U.ExpectedError, (500, "Unexpected request method `%s'" % METHOD)
 
   ## Populate the `SPECIAL', `PARAM' and `PARAMDICT' tables.
   seen = set()