From 2d3b2fc9c6a7b60ddf091e05b87ccdcaaea9b77c Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Fri, 5 Mar 2021 12:30:31 +0200 Subject: [PATCH 1/3] Use HHP method table from ESP-IDF's nghttp --- libraries/WebServer/src/HTTP_Method.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/libraries/WebServer/src/HTTP_Method.h b/libraries/WebServer/src/HTTP_Method.h index 4532332bc88..66d53bf87a0 100644 --- a/libraries/WebServer/src/HTTP_Method.h +++ b/libraries/WebServer/src/HTTP_Method.h @@ -1,15 +1,9 @@ #ifndef _HTTP_Method_H_ #define _HTTP_Method_H_ -typedef enum { - HTTP_GET = 0b00000001, - HTTP_POST = 0b00000010, - HTTP_DELETE = 0b00000100, - HTTP_PUT = 0b00001000, - HTTP_PATCH = 0b00010000, - HTTP_HEAD = 0b00100000, - HTTP_OPTIONS = 0b01000000, - HTTP_ANY = 0b01111111, -} HTTPMethod; +#include "http_parser.h" + +typedef enum http_method HTTPMethod; +#define HTTP_ANY (HTTPMethod)(255) #endif /* _HTTP_Method_H_ */ From e64de5476e34114a91f65f151f7db3d81a66355d Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Fri, 5 Mar 2021 13:21:58 +0200 Subject: [PATCH 2/3] Parse methods using IDF's HTTP method list --- libraries/WebServer/src/Parsing.cpp | 30 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/libraries/WebServer/src/Parsing.cpp b/libraries/WebServer/src/Parsing.cpp index ef455c8ab65..a5bfb0710bd 100644 --- a/libraries/WebServer/src/Parsing.cpp +++ b/libraries/WebServer/src/Parsing.cpp @@ -30,6 +30,14 @@ #define WEBSERVER_MAX_POST_ARGS 32 #endif +#define __STR(a) #a +#define _STR(a) __STR(a) +const char * _http_method_str[] = { +#define XX(num, name, string) _STR(name), + HTTP_METHOD_MAP(XX) +#undef XX +}; + static const char Content_Type[] PROGMEM = "Content-Type"; static const char filename[] PROGMEM = "filename"; @@ -96,17 +104,17 @@ bool WebServer::_parseRequest(WiFiClient& client) { _currentUri = url; _chunked = false; - HTTPMethod method = HTTP_GET; - if (methodStr == F("POST")) { - method = HTTP_POST; - } else if (methodStr == F("DELETE")) { - method = HTTP_DELETE; - } else if (methodStr == F("OPTIONS")) { - method = HTTP_OPTIONS; - } else if (methodStr == F("PUT")) { - method = HTTP_PUT; - } else if (methodStr == F("PATCH")) { - method = HTTP_PATCH; + HTTPMethod method = HTTP_ANY; + size_t num_methods = sizeof(_http_method_str) / sizeof(const char *); + for (size_t i=0; i Date: Fri, 5 Mar 2021 13:22:36 +0200 Subject: [PATCH 3/3] Make example's loops to allow the CPU to switch tasks --- .../WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino | 1 + libraries/WebServer/examples/FSBrowser/FSBrowser.ino | 1 + libraries/WebServer/examples/HelloServer/HelloServer.ino | 1 + .../WebServer/examples/HttpAdvancedAuth/HttpAdvancedAuth.ino | 1 + libraries/WebServer/examples/HttpBasicAuth/HttpBasicAuth.ino | 1 + libraries/WebServer/examples/PathArgServer/PathArgServer.ino | 1 + libraries/WebServer/examples/SDWebServer/SDWebServer.ino | 1 + .../examples/SimpleAuthentification/SimpleAuthentification.ino | 1 + libraries/WebServer/examples/WebUpdate/WebUpdate.ino | 2 +- 9 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino b/libraries/WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino index 88ad6c8a08d..e8e8153647a 100644 --- a/libraries/WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino +++ b/libraries/WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino @@ -125,6 +125,7 @@ void setup(void) { void loop(void) { server.handleClient(); + delay(2);//allow the cpu to switch to other tasks } void drawGraph() { diff --git a/libraries/WebServer/examples/FSBrowser/FSBrowser.ino b/libraries/WebServer/examples/FSBrowser/FSBrowser.ino index f49ae81c158..f33f5dbe233 100644 --- a/libraries/WebServer/examples/FSBrowser/FSBrowser.ino +++ b/libraries/WebServer/examples/FSBrowser/FSBrowser.ino @@ -300,4 +300,5 @@ void setup(void) { void loop(void) { server.handleClient(); + delay(2);//allow the cpu to switch to other tasks } diff --git a/libraries/WebServer/examples/HelloServer/HelloServer.ino b/libraries/WebServer/examples/HelloServer/HelloServer.ino index 1a1180c2593..d807ff089b9 100644 --- a/libraries/WebServer/examples/HelloServer/HelloServer.ino +++ b/libraries/WebServer/examples/HelloServer/HelloServer.ino @@ -70,4 +70,5 @@ void setup(void) { void loop(void) { server.handleClient(); + delay(2);//allow the cpu to switch to other tasks } diff --git a/libraries/WebServer/examples/HttpAdvancedAuth/HttpAdvancedAuth.ino b/libraries/WebServer/examples/HttpAdvancedAuth/HttpAdvancedAuth.ino index 567fd487863..e2af95508ba 100644 --- a/libraries/WebServer/examples/HttpAdvancedAuth/HttpAdvancedAuth.ino +++ b/libraries/WebServer/examples/HttpAdvancedAuth/HttpAdvancedAuth.ino @@ -56,4 +56,5 @@ void setup() { void loop() { ArduinoOTA.handle(); server.handleClient(); + delay(2);//allow the cpu to switch to other tasks } diff --git a/libraries/WebServer/examples/HttpBasicAuth/HttpBasicAuth.ino b/libraries/WebServer/examples/HttpBasicAuth/HttpBasicAuth.ino index 7a7dcc9a5e3..a370a24554d 100644 --- a/libraries/WebServer/examples/HttpBasicAuth/HttpBasicAuth.ino +++ b/libraries/WebServer/examples/HttpBasicAuth/HttpBasicAuth.ino @@ -38,4 +38,5 @@ void setup() { void loop() { ArduinoOTA.handle(); server.handleClient(); + delay(2);//allow the cpu to switch to other tasks } diff --git a/libraries/WebServer/examples/PathArgServer/PathArgServer.ino b/libraries/WebServer/examples/PathArgServer/PathArgServer.ino index 0b4dc425869..8482b2df63d 100644 --- a/libraries/WebServer/examples/PathArgServer/PathArgServer.ino +++ b/libraries/WebServer/examples/PathArgServer/PathArgServer.ino @@ -53,4 +53,5 @@ void setup(void) { void loop(void) { server.handleClient(); + delay(2);//allow the cpu to switch to other tasks } diff --git a/libraries/WebServer/examples/SDWebServer/SDWebServer.ino b/libraries/WebServer/examples/SDWebServer/SDWebServer.ino index a3271a03740..3d0e3942fb1 100644 --- a/libraries/WebServer/examples/SDWebServer/SDWebServer.ino +++ b/libraries/WebServer/examples/SDWebServer/SDWebServer.ino @@ -310,4 +310,5 @@ void setup(void) { void loop(void) { server.handleClient(); + delay(2);//allow the cpu to switch to other tasks } diff --git a/libraries/WebServer/examples/SimpleAuthentification/SimpleAuthentification.ino b/libraries/WebServer/examples/SimpleAuthentification/SimpleAuthentification.ino index 1adf20613ad..98cb62ebe15 100644 --- a/libraries/WebServer/examples/SimpleAuthentification/SimpleAuthentification.ino +++ b/libraries/WebServer/examples/SimpleAuthentification/SimpleAuthentification.ino @@ -129,4 +129,5 @@ void setup(void) { void loop(void) { server.handleClient(); + delay(2);//allow the cpu to switch to other tasks } diff --git a/libraries/WebServer/examples/WebUpdate/WebUpdate.ino b/libraries/WebServer/examples/WebUpdate/WebUpdate.ino index 843867d5f3b..a3ae1f8a1ab 100644 --- a/libraries/WebServer/examples/WebUpdate/WebUpdate.ino +++ b/libraries/WebServer/examples/WebUpdate/WebUpdate.ino @@ -65,5 +65,5 @@ void setup(void) { void loop(void) { server.handleClient(); - delay(1); + delay(2);//allow the cpu to switch to other tasks }