Skip to content

Commit e64de54

Browse files
committed
Parse methods using IDF's HTTP method list
1 parent 2d3b2fc commit e64de54

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

libraries/WebServer/src/Parsing.cpp

+19-11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
#define WEBSERVER_MAX_POST_ARGS 32
3131
#endif
3232

33+
#define __STR(a) #a
34+
#define _STR(a) __STR(a)
35+
const char * _http_method_str[] = {
36+
#define XX(num, name, string) _STR(name),
37+
HTTP_METHOD_MAP(XX)
38+
#undef XX
39+
};
40+
3341
static const char Content_Type[] PROGMEM = "Content-Type";
3442
static const char filename[] PROGMEM = "filename";
3543

@@ -96,17 +104,17 @@ bool WebServer::_parseRequest(WiFiClient& client) {
96104
_currentUri = url;
97105
_chunked = false;
98106

99-
HTTPMethod method = HTTP_GET;
100-
if (methodStr == F("POST")) {
101-
method = HTTP_POST;
102-
} else if (methodStr == F("DELETE")) {
103-
method = HTTP_DELETE;
104-
} else if (methodStr == F("OPTIONS")) {
105-
method = HTTP_OPTIONS;
106-
} else if (methodStr == F("PUT")) {
107-
method = HTTP_PUT;
108-
} else if (methodStr == F("PATCH")) {
109-
method = HTTP_PATCH;
107+
HTTPMethod method = HTTP_ANY;
108+
size_t num_methods = sizeof(_http_method_str) / sizeof(const char *);
109+
for (size_t i=0; i<num_methods; i++) {
110+
if (methodStr == _http_method_str[i]) {
111+
method = (HTTPMethod)i;
112+
break;
113+
}
114+
}
115+
if (method == HTTP_ANY) {
116+
log_e("Unknown HTTP Method: %s", methodStr.c_str());
117+
return false;
110118
}
111119
_currentMethod = method;
112120

0 commit comments

Comments
 (0)