@@ -80,7 +80,7 @@ bool WebServer::_parseRequest(WiFiClient& client) {
80
80
// reset header value
81
81
for (int i = 0 ; i < _headerKeysCount; ++i) {
82
82
_currentHeaders[i].value =String ();
83
- }
83
+ }
84
84
85
85
// First line of HTTP request looks like "GET /path HTTP/1.1"
86
86
// Retrieve the "/path" part by finding the spaces
@@ -103,6 +103,7 @@ bool WebServer::_parseRequest(WiFiClient& client) {
103
103
}
104
104
_currentUri = url;
105
105
_chunked = false ;
106
+ _clientContentLength = 0 ; // not known yet, or invalid
106
107
107
108
HTTPMethod method = HTTP_ANY;
108
109
size_t num_methods = sizeof (_http_method_str) / sizeof (const char *);
@@ -136,7 +137,6 @@ bool WebServer::_parseRequest(WiFiClient& client) {
136
137
String headerValue;
137
138
bool isForm = false ;
138
139
bool isEncoded = false ;
139
- uint32_t contentLength = 0 ;
140
140
// parse headers
141
141
while (1 ){
142
142
req = client.readStringUntil (' \r ' );
@@ -167,20 +167,20 @@ bool WebServer::_parseRequest(WiFiClient& client) {
167
167
isForm = true ;
168
168
}
169
169
} else if (headerName.equalsIgnoreCase (F (" Content-Length" ))){
170
- contentLength = headerValue.toInt ();
170
+ _clientContentLength = headerValue.toInt ();
171
171
} else if (headerName.equalsIgnoreCase (F (" Host" ))){
172
172
_hostHeader = headerValue;
173
173
}
174
174
}
175
175
176
176
if (!isForm){
177
177
size_t plainLength;
178
- char * plainBuf = readBytesWithTimeout (client, contentLength , plainLength, HTTP_MAX_POST_WAIT);
179
- if (plainLength < contentLength ) {
178
+ char * plainBuf = readBytesWithTimeout (client, _clientContentLength , plainLength, HTTP_MAX_POST_WAIT);
179
+ if (plainLength < _clientContentLength ) {
180
180
free (plainBuf);
181
181
return false ;
182
182
}
183
- if (contentLength > 0 ) {
183
+ if (_clientContentLength > 0 ) {
184
184
if (isEncoded){
185
185
// url encoded form
186
186
if (searchStr != " " ) searchStr += ' &' ;
@@ -200,11 +200,10 @@ bool WebServer::_parseRequest(WiFiClient& client) {
200
200
// No content - but we can still have arguments in the URL.
201
201
_parseArguments (searchStr);
202
202
}
203
- }
204
-
205
- if (isForm){
203
+ } else {
204
+ // it IS a form
206
205
_parseArguments (searchStr);
207
- if (!_parseForm (client, boundaryStr, contentLength )) {
206
+ if (!_parseForm (client, boundaryStr, _clientContentLength )) {
208
207
return false ;
209
208
}
210
209
}
0 commit comments