Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ void setup(void) {

void loop(void) {
server.handleClient();
delay(2);//allow the cpu to switch to other tasks
}

void drawGraph() {
Expand Down
1 change: 1 addition & 0 deletions libraries/WebServer/examples/FSBrowser/FSBrowser.ino
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,5 @@ void setup(void) {

void loop(void) {
server.handleClient();
delay(2);//allow the cpu to switch to other tasks
}
1 change: 1 addition & 0 deletions libraries/WebServer/examples/HelloServer/HelloServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ void setup(void) {

void loop(void) {
server.handleClient();
delay(2);//allow the cpu to switch to other tasks
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ void setup() {
void loop() {
ArduinoOTA.handle();
server.handleClient();
delay(2);//allow the cpu to switch to other tasks
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ void setup() {
void loop() {
ArduinoOTA.handle();
server.handleClient();
delay(2);//allow the cpu to switch to other tasks
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ void setup(void) {

void loop(void) {
server.handleClient();
delay(2);//allow the cpu to switch to other tasks
}
1 change: 1 addition & 0 deletions libraries/WebServer/examples/SDWebServer/SDWebServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,5 @@ void setup(void) {

void loop(void) {
server.handleClient();
delay(2);//allow the cpu to switch to other tasks
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ void setup(void) {

void loop(void) {
server.handleClient();
delay(2);//allow the cpu to switch to other tasks
}
2 changes: 1 addition & 1 deletion libraries/WebServer/examples/WebUpdate/WebUpdate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ void setup(void) {

void loop(void) {
server.handleClient();
delay(1);
delay(2);//allow the cpu to switch to other tasks
}
14 changes: 4 additions & 10 deletions libraries/WebServer/src/HTTP_Method.h
Original file line number Diff line number Diff line change
@@ -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_ */
30 changes: 19 additions & 11 deletions libraries/WebServer/src/Parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<num_methods; i++) {
if (methodStr == _http_method_str[i]) {
method = (HTTPMethod)i;
break;
}
}
if (method == HTTP_ANY) {
log_e("Unknown HTTP Method: %s", methodStr.c_str());
return false;
}
_currentMethod = method;

Expand Down