Use HTTP method table from ESP-IDF's nghttp (#4900)

Fixes: #4884

* Use HTTP method table from ESP-IDF's nghttp
* Parse methods using IDF's HTTP method list
* Make example's loops to allow the CPU to switch tasks
This commit is contained in:
Me No Dev 2021-03-05 13:40:52 +02:00 committed by GitHub
parent dd834b3372
commit f7fc8ab377
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 32 additions and 22 deletions

View File

@ -125,6 +125,7 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
delay(2);//allow the cpu to switch to other tasks
} }
void drawGraph() { void drawGraph() {

View File

@ -300,4 +300,5 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
delay(2);//allow the cpu to switch to other tasks
} }

View File

@ -70,4 +70,5 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
delay(2);//allow the cpu to switch to other tasks
} }

View File

@ -56,4 +56,5 @@ void setup() {
void loop() { void loop() {
ArduinoOTA.handle(); ArduinoOTA.handle();
server.handleClient(); server.handleClient();
delay(2);//allow the cpu to switch to other tasks
} }

View File

@ -38,4 +38,5 @@ void setup() {
void loop() { void loop() {
ArduinoOTA.handle(); ArduinoOTA.handle();
server.handleClient(); server.handleClient();
delay(2);//allow the cpu to switch to other tasks
} }

View File

@ -53,4 +53,5 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
delay(2);//allow the cpu to switch to other tasks
} }

View File

@ -310,4 +310,5 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
delay(2);//allow the cpu to switch to other tasks
} }

View File

@ -129,4 +129,5 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
delay(2);//allow the cpu to switch to other tasks
} }

View File

@ -65,5 +65,5 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
delay(1); delay(2);//allow the cpu to switch to other tasks
} }

View File

@ -1,15 +1,9 @@
#ifndef _HTTP_Method_H_ #ifndef _HTTP_Method_H_
#define _HTTP_Method_H_ #define _HTTP_Method_H_
typedef enum { #include "http_parser.h"
HTTP_GET = 0b00000001,
HTTP_POST = 0b00000010, typedef enum http_method HTTPMethod;
HTTP_DELETE = 0b00000100, #define HTTP_ANY (HTTPMethod)(255)
HTTP_PUT = 0b00001000,
HTTP_PATCH = 0b00010000,
HTTP_HEAD = 0b00100000,
HTTP_OPTIONS = 0b01000000,
HTTP_ANY = 0b01111111,
} HTTPMethod;
#endif /* _HTTP_Method_H_ */ #endif /* _HTTP_Method_H_ */

View File

@ -30,6 +30,14 @@
#define WEBSERVER_MAX_POST_ARGS 32 #define WEBSERVER_MAX_POST_ARGS 32
#endif #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 Content_Type[] PROGMEM = "Content-Type";
static const char filename[] PROGMEM = "filename"; static const char filename[] PROGMEM = "filename";
@ -96,17 +104,17 @@ bool WebServer::_parseRequest(WiFiClient& client) {
_currentUri = url; _currentUri = url;
_chunked = false; _chunked = false;
HTTPMethod method = HTTP_GET; HTTPMethod method = HTTP_ANY;
if (methodStr == F("POST")) { size_t num_methods = sizeof(_http_method_str) / sizeof(const char *);
method = HTTP_POST; for (size_t i=0; i<num_methods; i++) {
} else if (methodStr == F("DELETE")) { if (methodStr == _http_method_str[i]) {
method = HTTP_DELETE; method = (HTTPMethod)i;
} else if (methodStr == F("OPTIONS")) { break;
method = HTTP_OPTIONS; }
} else if (methodStr == F("PUT")) { }
method = HTTP_PUT; if (method == HTTP_ANY) {
} else if (methodStr == F("PATCH")) { log_e("Unknown HTTP Method: %s", methodStr.c_str());
method = HTTP_PATCH; return false;
} }
_currentMethod = method; _currentMethod = method;