From 8d2b1fdfafd8d13a03273bdcd10c426dde6020cb Mon Sep 17 00:00:00 2001 From: Lammert Bies Date: Sun, 11 Dec 2016 00:10:10 +0100 Subject: [PATCH] Moved is valid_http_method to own file --- Makefile | 1 + src/httplib_is_valid_http_method.c | 64 ++++++++++++++++++++++++++++++ src/libhttp.c | 29 -------------- 3 files changed, 65 insertions(+), 29 deletions(-) create mode 100644 src/httplib_is_valid_http_method.c diff --git a/Makefile b/Makefile index 4cb0ff26..659907bb 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,7 @@ LIB_SOURCES = src/libhttp.c \ src/httplib_handle_websocket_request.c \ src/httplib_initialize_ssl.c \ src/httplib_is_not_modified.c \ + src/httplib_is_valid_http_method.c \ src/httplib_is_websocket_protocol.c \ src/httplib_load_dll.c \ src/httplib_lock_unlock_connection.c \ diff --git a/src/httplib_is_valid_http_method.c b/src/httplib_is_valid_http_method.c new file mode 100644 index 00000000..11cd2670 --- /dev/null +++ b/src/httplib_is_valid_http_method.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016 Lammert Bies + * Copyright (c) 2013-2016 the Civetweb developers + * Copyright (c) 2004-2013 Sergey Lyubka + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + + +#include "libhttp-private.h" + + + +/* + * int XX_httplib_is_valid_http_method( const char *method ); + * + * The function XX_httplib_is_valid_http_method() checks if the method in a + * request is a valid method. + */ + +int XX_httplib_is_valid_http_method( const char *method ) { + + return !strcmp(method, "GET") /* HTTP (RFC 2616) */ + || !strcmp(method, "POST") /* HTTP (RFC 2616) */ + || !strcmp(method, "HEAD") /* HTTP (RFC 2616) */ + || !strcmp(method, "PUT") /* HTTP (RFC 2616) */ + || !strcmp(method, "DELETE") /* HTTP (RFC 2616) */ + || !strcmp(method, "OPTIONS") /* HTTP (RFC 2616) */ + /* TRACE method (RFC 2616) is not supported for security reasons */ + || !strcmp(method, "CONNECT") /* HTTP (RFC 2616) */ + + || !strcmp(method, "PROPFIND") /* WEBDAV (RFC 2518) */ + || !strcmp(method, "MKCOL") /* WEBDAV (RFC 2518) */ + + /* Unsupported WEBDAV Methods: */ + /* PROPPATCH, COPY, MOVE, LOCK, UNLOCK (RFC 2518) */ + /* + 11 methods from RFC 3253 */ + /* ORDERPATCH (RFC 3648) */ + /* ACL (RFC 3744) */ + /* SEARCH (RFC 5323) */ + /* + MicroSoft extensions + * 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) */ + +} /* XX_httplib_is_valid_http_method */ diff --git a/src/libhttp.c b/src/libhttp.c index 868da798..7fc3d6c4 100644 --- a/src/libhttp.c +++ b/src/libhttp.c @@ -5250,32 +5250,3 @@ int XX_httplib_parse_http_headers( char **buf, struct mg_request_info *ri ) { return ri->num_headers; } /* XX_httplib_parse_http_headers */ - - -int XX_httplib_is_valid_http_method( const char *method ) { - - return !strcmp(method, "GET") /* HTTP (RFC 2616) */ - || !strcmp(method, "POST") /* HTTP (RFC 2616) */ - || !strcmp(method, "HEAD") /* HTTP (RFC 2616) */ - || !strcmp(method, "PUT") /* HTTP (RFC 2616) */ - || !strcmp(method, "DELETE") /* HTTP (RFC 2616) */ - || !strcmp(method, "OPTIONS") /* HTTP (RFC 2616) */ - /* TRACE method (RFC 2616) is not supported for security reasons */ - || !strcmp(method, "CONNECT") /* HTTP (RFC 2616) */ - - || !strcmp(method, "PROPFIND") /* WEBDAV (RFC 2518) */ - || !strcmp(method, "MKCOL") /* WEBDAV (RFC 2518) */ - - /* Unsupported WEBDAV Methods: */ - /* PROPPATCH, COPY, MOVE, LOCK, UNLOCK (RFC 2518) */ - /* + 11 methods from RFC 3253 */ - /* ORDERPATCH (RFC 3648) */ - /* ACL (RFC 3744) */ - /* SEARCH (RFC 5323) */ - /* + MicroSoft extensions - * 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) */ - -} /* XX_httplib_is_valid_http_method */