@@ -81,6 +81,14 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
81
81
DEBUG_OUTPUT.println (searchStr);
82
82
#endif
83
83
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
+
84
92
String formData;
85
93
// below is needed only when POST type request
86
94
if (method == HTTP_POST || method == HTTP_PUT || method == HTTP_PATCH || method == HTTP_DELETE){
@@ -279,7 +287,8 @@ void ESP8266WebServer::_parseArguments(String data) {
279
287
280
288
void ESP8266WebServer::_uploadWriteByte (uint8_t b){
281
289
if (_currentUpload.currentSize == HTTP_UPLOAD_BUFLEN){
282
- if (_fileUploadHandler) _fileUploadHandler ();
290
+ if (_currentHandler && _currentHandler->canUpload (_currentUri))
291
+ _currentHandler->upload (*this , _currentUri, _currentUpload);
283
292
_currentUpload.totalSize += _currentUpload.currentSize ;
284
293
_currentUpload.currentSize = 0 ;
285
294
}
@@ -397,7 +406,8 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
397
406
DEBUG_OUTPUT.print (" Type: " );
398
407
DEBUG_OUTPUT.println (_currentUpload.type );
399
408
#endif
400
- if (_fileUploadHandler) _fileUploadHandler ();
409
+ if (_currentHandler && _currentHandler->canUpload (_currentUri))
410
+ _currentHandler->upload (*this , _currentUri, _currentUpload);
401
411
_currentUpload.status = UPLOAD_FILE_WRITE;
402
412
uint8_t argByte = _uploadReadByte (client);
403
413
readfile:
@@ -433,10 +443,12 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
433
443
client.readBytes (endBuf, boundary.length ());
434
444
435
445
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);
437
448
_currentUpload.totalSize += _currentUpload.currentSize ;
438
449
_currentUpload.status = UPLOAD_FILE_END;
439
- if (_fileUploadHandler) _fileUploadHandler ();
450
+ if (_currentHandler && _currentHandler->canUpload (_currentUri))
451
+ _currentHandler->upload (*this , _currentUri, _currentUpload);
440
452
#ifdef DEBUG
441
453
DEBUG_OUTPUT.print (" End File: " );
442
454
DEBUG_OUTPUT.print (_currentUpload.filename );
@@ -503,6 +515,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
503
515
504
516
bool ESP8266WebServer::_parseFormUploadAborted (){
505
517
_currentUpload.status = UPLOAD_FILE_ABORTED;
506
- if (_fileUploadHandler) _fileUploadHandler ();
518
+ if (_currentHandler && _currentHandler->canUpload (_currentUri))
519
+ _currentHandler->upload (*this , _currentUri, _currentUpload);
507
520
return false ;
508
521
}
0 commit comments