@@ -91,7 +91,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
91
91
String searchStr = " " ;
92
92
int hasSearch = url.indexOf (' ?' );
93
93
if (hasSearch != -1 ){
94
- searchStr = url.substring (hasSearch + 1 );
94
+ searchStr = urlDecode ( url.substring (hasSearch + 1 ) );
95
95
url = url.substring (0 , hasSearch);
96
96
}
97
97
_currentUri = url;
@@ -135,6 +135,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
135
135
String headerName;
136
136
String headerValue;
137
137
bool isForm = false ;
138
+ bool isEncoded = false ;
138
139
uint32_t contentLength = 0 ;
139
140
// parse headers
140
141
while (1 ){
@@ -150,17 +151,20 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
150
151
headerValue.trim ();
151
152
_collectHeader (headerName.c_str (),headerValue.c_str ());
152
153
153
- #ifdef DEBUG_ESP_HTTP_SERVER
154
- DEBUG_OUTPUT.print (" headerName: " );
155
- DEBUG_OUTPUT.println (headerName);
156
- DEBUG_OUTPUT.print (" headerValue: " );
157
- DEBUG_OUTPUT.println (headerValue);
158
- #endif
154
+ #ifdef DEBUG_ESP_HTTP_SERVER
155
+ DEBUG_OUTPUT.print (" headerName: " );
156
+ DEBUG_OUTPUT.println (headerName);
157
+ DEBUG_OUTPUT.print (" headerValue: " );
158
+ DEBUG_OUTPUT.println (headerValue);
159
+ #endif
159
160
160
161
if (headerName == " Content-Type" ){
161
162
if (headerValue.startsWith (" text/plain" )){
162
163
isForm = false ;
163
- } else if (headerValue.startsWith (" multipart/form-data" )){
164
+ } else if (headerValue.startsWith (" application/x-www-form-urlencoded" )){
165
+ isForm = false ;
166
+ isEncoded = true ;
167
+ } else if (headerValue.startsWith (" multipart/" )){
164
168
boundaryStr = headerValue.substring (headerValue.indexOf (' =' )+1 );
165
169
isForm = true ;
166
170
}
@@ -178,19 +182,22 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
178
182
free (plainBuf);
179
183
return false ;
180
184
}
181
- #ifdef DEBUG_ESP_HTTP_SERVER
182
- DEBUG_OUTPUT.print (" Plain: " );
183
- DEBUG_OUTPUT.println (plainBuf);
184
- #endif
185
185
if (contentLength > 0 ) {
186
- if (searchStr != " " ) searchStr += ' &' ;
187
- if (plainBuf[0 ] == ' {' || plainBuf[0 ] == ' [' || strstr (plainBuf, " =" ) == NULL ){
186
+ if (isEncoded){
187
+ // url encoded form
188
+ String decoded = urlDecode (plainBuf);
189
+ size_t decodedLen = decoded.length ();
190
+ memcpy (plainBuf, decoded.c_str (), decodedLen);
191
+ plainBuf[decodedLen] = 0 ;
192
+ } else {
188
193
// plain post json or other data
189
194
searchStr += " plain=" ;
190
- searchStr += plainBuf;
191
- } else {
192
- searchStr += plainBuf;
193
195
}
196
+ searchStr += plainBuf;
197
+ #ifdef DEBUG_ESP_HTTP_SERVER
198
+ DEBUG_OUTPUT.print (" Plain: " );
199
+ DEBUG_OUTPUT.println (plainBuf);
200
+ #endif
194
201
free (plainBuf);
195
202
}
196
203
}
@@ -303,7 +310,7 @@ void ESP8266WebServer::_parseArguments(String data) {
303
310
}
304
311
RequestArgument& arg = _currentArgs[iarg];
305
312
arg.key = data.substring (pos, equal_sign_index);
306
- arg.value = urlDecode ( data.substring (equal_sign_index + 1 , next_arg_index) );
313
+ arg.value = data.substring (equal_sign_index + 1 , next_arg_index);
307
314
#ifdef DEBUG_ESP_HTTP_SERVER
308
315
DEBUG_OUTPUT.print (" arg " );
309
316
DEBUG_OUTPUT.print (iarg);
0 commit comments