Cosmetic fiddling.
[chopwood] / cgi.py
diff --git a/cgi.py b/cgi.py
index 01fb868..cfa26f7 100644 (file)
--- a/cgi.py
+++ b/cgi.py
@@ -401,7 +401,8 @@ def cgiparse():
     if not n.isdigit():
       raise U.ExpectedError, (500, "Invalid CONTENT_LENGTH")
     n = int(n, 10)
-    if getenv('CONTENT_TYPE') != 'application/x-www-form-urlencoded':
+    ct = getenv('CONTENT_TYPE')
+    if ct != 'application/x-www-form-urlencoded':
       raise U.ExpectedError, (500, "Unexpected content type `%s'" % ct)
     q = SYS.stdin.read(n)
     if len(q) != n:
@@ -452,6 +453,11 @@ class Subcommand (SC.Subcommand):
   CGI parameters.
   """
 
+  def __init__(me, name, contexts, desc, func,
+               methods = ['GET', 'POST'], *args, **kw):
+    super(Subcommand, me).__init__(name, contexts, desc, func, *args, **kw)
+    me.methods = set(methods)
+
   def cgi(me, param, path):
     """
     Invoke the subcommand given a collection of CGI parameters.
@@ -483,6 +489,12 @@ class Subcommand (SC.Subcommand):
     want = {}
     kw = {}
 
+    ## Check the request method against the permitted list.
+    meth = METHOD
+    if meth == 'HEAD': meth = 'GET'
+    if meth not in me.methods:
+      raise U.ExpectedError, (500, "Unexpected request method `%s'" % METHOD)
+
     def set_value(k, v):
       """Set a simple value: we shouldn't see multiple values."""
       if k in kw: