Browse Source

HTTP POST requests to static files must return 405

Fix for a bug recently introduced in a redesign of the request handling.
Fix for a request method test page.
bel 10 years ago
parent
commit
4040ba73f9
2 changed files with 14 additions and 7 deletions
  1. 2 2
      src/civetweb.c
  2. 12 5
      test/MethodTest.xhtml

+ 2 - 2
src/civetweb.c

@@ -6320,8 +6320,8 @@ static void handle_request(struct mg_connection *conn)
         return;
     }
     /* 13.3. everything but GET and HEAD (e.g. POST) */
-    if (!strcmp(ri->request_method, "GET") &&
-        !strcmp(ri->request_method, "HEAD")) {
+    if (0!=strcmp(ri->request_method, "GET") &&
+        0!=strcmp(ri->request_method, "HEAD")) {
         send_http_error(conn, 405, NULL,
             "%s method not allowed", conn->request_info.request_method);
         return;

+ 12 - 5
test/MethodTest.xhtml

@@ -25,10 +25,14 @@
 
     function load() {
         var params = getParams();
-        method = params["method"];
+        var method = params["method"];
         if (!method) {
           method = "GET";
         }
+        var path = params["path"];
+        if (!path) {
+          path = "";
+        }
 
         var elem = document.getElementById('h1');
         elem.innerHTML = "HTTP method test page";
@@ -36,7 +40,7 @@
         document.getElementById("proto_http").checked = (window.location.protocol != "https:");
         document.getElementById("proto_https").checked = (window.location.protocol == "https:");
         document.getElementById("server").value = location.host;
-        document.getElementById("resource").value = "path";
+        document.getElementById("resource").value = path;
 
         document.getElementById("method_get").checked = true;
         document.getElementById("body_none").checked = true;
@@ -82,7 +86,10 @@
         {
             var laddr = addr
             var lmeth = meth
-            var blen = "\nWith " + body.length + " bytes body data"
+            var blen = ""
+            if (body) {
+              blen = "\nWith " + body.length + " bytes body data"
+            }
             
             if (xmlhttp.readyState == 4)
             {
@@ -133,8 +140,8 @@ TODO: Description how to use this page.
 <input id="method_inv" type="radio" name="method" value="INVALID" />*INVALID*
 
 <h3>Body data</h3>
-<input id="body_none" type="radio" name="body" value="*" />*none* <br />
-<input id="body_10" type="radio" name="body" value="1234567890" />1234567890 <br />
+<input id="body_none" type="radio" name="body" value="*" />0 Bytes <br />
+<input id="body_10" type="radio" name="body" value="1234567890" />10 Bytes ("1234567890") <br />
 
 
 <h3>Submit</h3>