File tree 3 files changed +10
-3
lines changed
libraries/ESP8266WebServer/src
3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -320,7 +320,6 @@ void ESP8266WebServerTemplate<ServerType>::handleClient() {
320
320
_currentClient = client;
321
321
_currentStatus = HC_WAIT_READ;
322
322
_statusChange = millis ();
323
- _keepAlive = true ;
324
323
}
325
324
326
325
bool keepCurrentClient = false ;
Original file line number Diff line number Diff line change @@ -170,8 +170,9 @@ class ESP8266WebServerTemplate
170
170
171
171
// Whether other requests should be accepted from the client on the
172
172
// same socket after a response is sent.
173
- // This will automatically configure the "Connection" header.
174
- // Defaults to false.
173
+ // This will automatically configure the "Connection" header of the response.
174
+ // Defaults to true when the client's HTTP version is 1.1 or above, otherwise it defaults to false.
175
+ // If the client sends the "Connection" header, the value given by the header is used.
175
176
void keepAlive (bool keepAlive) { _keepAlive = keepAlive; }
176
177
bool keepAlive () { return _keepAlive; }
177
178
Original file line number Diff line number Diff line change @@ -114,6 +114,9 @@ bool ESP8266WebServerTemplate<ServerType>::_parseRequest(ClientType& client) {
114
114
}
115
115
_currentMethod = method;
116
116
117
+ _keepAlive = _currentVersion > 0 ; // Keep the connection alive by default
118
+ // if the protocol version is greater than HTTP 1.0
119
+
117
120
#ifdef DEBUG_ESP_HTTP_SERVER
118
121
DEBUG_OUTPUT.print (" method: " );
119
122
DEBUG_OUTPUT.print (methodStr);
@@ -177,6 +180,8 @@ bool ESP8266WebServerTemplate<ServerType>::_parseRequest(ClientType& client) {
177
180
contentLength = headerValue.toInt ();
178
181
} else if (headerName.equalsIgnoreCase (F (" Host" ))){
179
182
_hostHeader = headerValue;
183
+ } else if (headerName.equalsIgnoreCase (F (" Connection" ))){
184
+ _keepAlive = headerValue.equalsIgnoreCase (F (" keep-alive" ));
180
185
}
181
186
}
182
187
@@ -240,6 +245,8 @@ bool ESP8266WebServerTemplate<ServerType>::_parseRequest(ClientType& client) {
240
245
241
246
if (headerName.equalsIgnoreCase (F (" Host" ))){
242
247
_hostHeader = headerValue;
248
+ } else if (headerName.equalsIgnoreCase (F (" Connection" ))){
249
+ _keepAlive = headerValue.equalsIgnoreCase (F (" keep-alive" ));
243
250
}
244
251
}
245
252
_parseArguments (searchStr);
You can’t perform that action at this time.
0 commit comments