File tree 1 file changed +19
-11
lines changed
1 file changed +19
-11
lines changed Original file line number Diff line number Diff line change 30
30
#define WEBSERVER_MAX_POST_ARGS 32
31
31
#endif
32
32
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
+
33
41
static const char Content_Type[] PROGMEM = " Content-Type" ;
34
42
static const char filename[] PROGMEM = " filename" ;
35
43
@@ -96,17 +104,17 @@ bool WebServer::_parseRequest(WiFiClient& client) {
96
104
_currentUri = url;
97
105
_chunked = false ;
98
106
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 ;
110
118
}
111
119
_currentMethod = method;
112
120
You can’t perform that action at this time.
0 commit comments