mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-15 00:02:49 +03:00
WebServer: Allow client to send many requests on the same connection (#7414)
* WebServer: Allow client to send many requests on the same connection * WebServer: Keep the connection alive with a client by default * WebServer: Use the request's HTTP version and Connection header to set the default keep alive value * Fix a typo in a comment
This commit is contained in:
committed by
GitHub
parent
709ba7981e
commit
3c1bd65a76
@ -49,6 +49,7 @@ ESP8266WebServerTemplate<ServerType>::ESP8266WebServerTemplate(IPAddress addr, i
|
||||
, _currentVersion(0)
|
||||
, _currentStatus(HC_NONE)
|
||||
, _statusChange(0)
|
||||
, _keepAlive(false)
|
||||
, _currentHandler(nullptr)
|
||||
, _firstHandler(nullptr)
|
||||
, _lastHandler(nullptr)
|
||||
@ -327,6 +328,10 @@ void ESP8266WebServerTemplate<ServerType>::handleClient() {
|
||||
bool callYield = false;
|
||||
|
||||
if (_currentClient.connected() || _currentClient.available()) {
|
||||
if (_currentClient.available() && _keepAlive) {
|
||||
_currentStatus = HC_WAIT_READ;
|
||||
}
|
||||
|
||||
switch (_currentStatus) {
|
||||
case HC_NONE:
|
||||
// No-op to avoid C++ compiler warning
|
||||
@ -431,7 +436,14 @@ void ESP8266WebServerTemplate<ServerType>::_prepareHeader(String& response, int
|
||||
if (_corsEnabled) {
|
||||
sendHeader(String(F("Access-Control-Allow-Origin")), String("*"));
|
||||
}
|
||||
sendHeader(String(F("Connection")), String(F("close")));
|
||||
|
||||
if (_keepAlive && _server.hasClient()) { // Disable keep alive if another client is waiting.
|
||||
_keepAlive = false;
|
||||
}
|
||||
sendHeader(String(F("Connection")), String(_keepAlive ? F("keep-alive") : F("close")));
|
||||
if (_keepAlive) {
|
||||
sendHeader(String(F("Keep-Alive")), String(F("timeout=")) + HTTP_MAX_CLOSE_WAIT);
|
||||
}
|
||||
|
||||
response += _responseHeaders;
|
||||
response += "\r\n";
|
||||
|
Reference in New Issue
Block a user