@@ -81,6 +81,14 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
8181 DEBUG_OUTPUT.println (searchStr);
8282#endif
8383
84+ // attach handler
85+ RequestHandler* handler;
86+ for (handler = _firstHandler; handler; handler = handler->next ()) {
87+ if (handler->canHandle (_currentMethod, _currentUri))
88+ break ;
89+ }
90+ _currentHandler = handler;
91+
8492 String formData;
8593 // below is needed only when POST type request
8694 if (method == HTTP_POST || method == HTTP_PUT || method == HTTP_PATCH || method == HTTP_DELETE){
@@ -279,7 +287,8 @@ void ESP8266WebServer::_parseArguments(String data) {
279287
280288void ESP8266WebServer::_uploadWriteByte (uint8_t b){
281289 if (_currentUpload.currentSize == HTTP_UPLOAD_BUFLEN){
282- if (_fileUploadHandler) _fileUploadHandler ();
290+ if (_currentHandler && _currentHandler->canUpload (_currentUri))
291+ _currentHandler->upload (*this , _currentUri, _currentUpload);
283292 _currentUpload.totalSize += _currentUpload.currentSize ;
284293 _currentUpload.currentSize = 0 ;
285294 }
@@ -397,7 +406,8 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
397406 DEBUG_OUTPUT.print (" Type: " );
398407 DEBUG_OUTPUT.println (_currentUpload.type );
399408#endif
400- if (_fileUploadHandler) _fileUploadHandler ();
409+ if (_currentHandler && _currentHandler->canUpload (_currentUri))
410+ _currentHandler->upload (*this , _currentUri, _currentUpload);
401411 _currentUpload.status = UPLOAD_FILE_WRITE;
402412 uint8_t argByte = _uploadReadByte (client);
403413readfile:
@@ -433,10 +443,12 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
433443 client.readBytes (endBuf, boundary.length ());
434444
435445 if (strstr ((const char *)endBuf, boundary.c_str ()) != NULL ){
436- if (_fileUploadHandler) _fileUploadHandler ();
446+ if (_currentHandler && _currentHandler->canUpload (_currentUri))
447+ _currentHandler->upload (*this , _currentUri, _currentUpload);
437448 _currentUpload.totalSize += _currentUpload.currentSize ;
438449 _currentUpload.status = UPLOAD_FILE_END;
439- if (_fileUploadHandler) _fileUploadHandler ();
450+ if (_currentHandler && _currentHandler->canUpload (_currentUri))
451+ _currentHandler->upload (*this , _currentUri, _currentUpload);
440452#ifdef DEBUG
441453 DEBUG_OUTPUT.print (" End File: " );
442454 DEBUG_OUTPUT.print (_currentUpload.filename );
@@ -503,6 +515,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
503515
504516bool ESP8266WebServer::_parseFormUploadAborted (){
505517 _currentUpload.status = UPLOAD_FILE_ABORTED;
506- if (_fileUploadHandler) _fileUploadHandler ();
518+ if (_currentHandler && _currentHandler->canUpload (_currentUri))
519+ _currentHandler->upload (*this , _currentUri, _currentUpload);
507520 return false ;
508521}
0 commit comments