@@ -80,7 +80,7 @@ bool WebServer::_parseRequest(WiFiClient& client) {
8080 // reset header value
8181 for (int i = 0 ; i < _headerKeysCount; ++i) {
8282 _currentHeaders[i].value =String ();
83- }
83+ }
8484
8585 // First line of HTTP request looks like "GET /path HTTP/1.1"
8686 // Retrieve the "/path" part by finding the spaces
@@ -103,6 +103,7 @@ bool WebServer::_parseRequest(WiFiClient& client) {
103103 }
104104 _currentUri = url;
105105 _chunked = false ;
106+ _clientContentLength = 0 ; // not known yet, or invalid
106107
107108 HTTPMethod method = HTTP_ANY;
108109 size_t num_methods = sizeof (_http_method_str) / sizeof (const char *);
@@ -136,7 +137,6 @@ bool WebServer::_parseRequest(WiFiClient& client) {
136137 String headerValue;
137138 bool isForm = false ;
138139 bool isEncoded = false ;
139- uint32_t contentLength = 0 ;
140140 // parse headers
141141 while (1 ){
142142 req = client.readStringUntil (' \r ' );
@@ -167,20 +167,20 @@ bool WebServer::_parseRequest(WiFiClient& client) {
167167 isForm = true ;
168168 }
169169 } else if (headerName.equalsIgnoreCase (F (" Content-Length" ))){
170- contentLength = headerValue.toInt ();
170+ _clientContentLength = headerValue.toInt ();
171171 } else if (headerName.equalsIgnoreCase (F (" Host" ))){
172172 _hostHeader = headerValue;
173173 }
174174 }
175175
176176 if (!isForm){
177177 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 ) {
180180 free (plainBuf);
181181 return false ;
182182 }
183- if (contentLength > 0 ) {
183+ if (_clientContentLength > 0 ) {
184184 if (isEncoded){
185185 // url encoded form
186186 if (searchStr != " " ) searchStr += ' &' ;
@@ -200,11 +200,10 @@ bool WebServer::_parseRequest(WiFiClient& client) {
200200 // No content - but we can still have arguments in the URL.
201201 _parseArguments (searchStr);
202202 }
203- }
204-
205- if (isForm){
203+ } else {
204+ // it IS a form
206205 _parseArguments (searchStr);
207- if (!_parseForm (client, boundaryStr, contentLength )) {
206+ if (!_parseForm (client, boundaryStr, _clientContentLength )) {
208207 return false ;
209208 }
210209 }
0 commit comments