Jelajahi Sumber

Allow "REPORT" HTTP method for REST calls

Some requets in a RESTful API should be a "GET", but they have a lot
of parameters, too long for the query string. The "GET" method does not
allow BODY with semantic meaning, so you cannot add these parameters as
JSON body.
A commonly used alternative would be to use "POST", but "POST" is neither
save nor idempotent, so it cannot be cached. Furthermore the expected
meaning of the words "POST" and "GET" is completely different.

Alternatively one can use the safe and idempotent method "REPORT",
defined in RFC3253, Section 3.6., allowing to cache responses.
"REPORT" has a similar meaning than "GET".

This commit allows scripts to handle REPORT methods.
Otherwise the server would filter them as "405 Method Not Allowed".

See also the list of all registered methods:
http://www.iana.org/assignments/http-methods/http-methods.xhtml

API calls that would be a GET in a RESTful API, but require a lot of parameter
cannot be made as GET, since the
bel 8 tahun lalu
induk
melakukan
034008fe92
1 mengubah file dengan 15 tambahan dan 1 penghapusan
  1. 15 1
      src/civetweb.c

+ 15 - 1
src/civetweb.c

@@ -8178,6 +8178,11 @@ parse_http_headers(char **buf, struct mg_request_info *ri)
 static int
 is_valid_http_method(const char *method)
 {
+	/* Check if the method is known to the server. The list of all known
+	 * HTTP methods can be found here at
+	 * http://www.iana.org/assignments/http-methods/http-methods.xhtml
+	 */
+
 	return !strcmp(method, "GET")        /* HTTP (RFC 2616) */
 	       || !strcmp(method, "POST")    /* HTTP (RFC 2616) */
 	       || !strcmp(method, "HEAD")    /* HTTP (RFC 2616) */
@@ -8200,7 +8205,16 @@ is_valid_http_method(const char *method)
 	        * https://msdn.microsoft.com/en-us/library/aa142917.aspx */
 
 	       /* PATCH method only allowed for CGI/Lua/LSP and callbacks. */
-	       || !strcmp(method, "PATCH"); /* PATCH method (RFC 5789) */
+	       || !strcmp(method, "PATCH") /* PATCH method (RFC 5789) */
+
+	       /* REPORT method only allowed for CGI/Lua/LSP and callbacks. */
+	       /* It was defined for WEBDAV in RFC 3253, Sec. 3.6
+	        * (https://tools.ietf.org/html/rfc3253#section-3.6), but seems
+	        * to be useful for REST in case a "GET request with body" is
+	        * required. */
+	       || !strcmp(method, "REPORT") /* REPORT method (RFC 3253) */
+
+	    ;
 }