MCPcopy Create free account
hub / github.com/Heltec-Aaron-Lee/WiFi_Kit_series / handleClient

Method handleClient

libraries/WebServer/src/WebServer.cpp:419–503  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

417}
418
419void WebServer::handleClient() {
420 if (_currentStatus == HC_NONE) {
421 _currentClient = _server.accept();
422 if (!_currentClient) {
423 if (_nullDelay) {
424 delay(1);
425 }
426 return;
427 }
428
429 log_v("New client: client.localIP()=%s", _currentClient.localIP().toString().c_str());
430
431 _currentStatus = HC_WAIT_READ;
432 _statusChange = millis();
433 }
434
435 bool keepCurrentClient = false;
436 bool callYield = false;
437
438 if (_currentClient.connected()) {
439 switch (_currentStatus) {
440 case HC_NONE:
441 // No-op to avoid C++ compiler warning
442 break;
443 case HC_WAIT_READ:
444 // Wait for data from client to become available
445 if (_currentClient.available()) {
446 _currentClient.setTimeout(HTTP_MAX_SEND_WAIT); /* / 1000 removed, WifiClient setTimeout changed to ms */
447 if (_parseRequest(_currentClient)) {
448 _contentLength = CONTENT_LENGTH_NOT_SET;
449 _responseCode = 0;
450 _clearResponseHeaders();
451
452 // Run server-level middlewares
453 if (_chain) {
454 _chain->runChain(*this, [this]() {
455 return _handleRequest();
456 });
457 } else {
458 _handleRequest();
459 }
460
461 if (_currentClient.isSSE()) {
462 _currentStatus = HC_WAIT_CLOSE;
463 _statusChange = millis();
464 keepCurrentClient = true;
465 }
466 // Fix for issue with Chrome based browsers: https://github.com/espressif/arduino-esp32/issues/3652
467 // if (_currentClient.connected()) {
468 // _currentStatus = HC_WAIT_CLOSE;
469 // _statusChange = millis();
470 // keepCurrentClient = true;
471 // }
472 }
473 } else { // !_currentClient.available()
474 if (millis() - _statusChange <= HTTP_MAX_DATA_WAIT) {
475 keepCurrentClient = true;
476 }

Callers

nothing calls this directly

Calls 13

delayFunction · 0.85
millisFunction · 0.85
NetworkClientClass · 0.85
acceptMethod · 0.80
c_strMethod · 0.80
runChainMethod · 0.80
isSSEMethod · 0.80
toStringMethod · 0.45
localIPMethod · 0.45
connectedMethod · 0.45
availableMethod · 0.45
setTimeoutMethod · 0.45

Tested by

no test coverage detected