Skip to content

Commit 9e45256

Browse files
committed
Merge branch 'master' into webhook
2 parents 93f2fbd + c3c61a5 commit 9e45256

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+41
-4642
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
[submodule "tools/esptool"]
2020
path = tools/esptool
2121
url = https://github.com/espressif/esptool.git
22+
[submodule "libraries/Ethernet"]
23+
path = libraries/Ethernet
24+
url = https://github.com/arduino-libraries/Ethernet.git
2225
[submodule "tools/sdk/uzlib"]
2326
path = tools/sdk/uzlib
2427
url = https://github.com/earlephilhower/uzlib.git

libraries/ESP8266WebServer/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Other Function Calls
154154
155155
const String & uri(); // get the current uri
156156
HTTPMethod method(); // get the current method
157-
WiFiClient client(); // get the current client
157+
WiFiClient & client(); // get the current client
158158
HTTPUpload & upload(); // get the current upload
159159
void setContentLength(); // set content length
160160
void sendHeader(); // send HTTP header

libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ESP8266WebServerTemplate<ServerType>::ESP8266WebServerTemplate(IPAddress addr, i
4141
, _currentVersion(0)
4242
, _currentStatus(HC_NONE)
4343
, _statusChange(0)
44+
, _keepAlive(false)
4445
, _currentHandler(nullptr)
4546
, _firstHandler(nullptr)
4647
, _lastHandler(nullptr)
@@ -316,6 +317,10 @@ void ESP8266WebServerTemplate<ServerType>::handleClient() {
316317
"??");
317318

318319
if (_currentClient.connected() || _currentClient.available()) {
320+
if (_currentClient.available() && _keepAlive) {
321+
_currentStatus = HC_WAIT_READ;
322+
}
323+
319324
switch (_currentStatus) {
320325
case HC_NONE:
321326
// No-op to avoid C++ compiler warning
@@ -443,7 +448,14 @@ void ESP8266WebServerTemplate<ServerType>::_prepareHeader(String& response, int
443448
if (_corsEnabled) {
444449
sendHeader(String(F("Access-Control-Allow-Origin")), String("*"));
445450
}
446-
sendHeader(String(F("Connection")), String(F("close")));
451+
452+
if (_keepAlive && _server.hasClient()) { // Disable keep alive if another client is waiting.
453+
_keepAlive = false;
454+
}
455+
sendHeader(String(F("Connection")), String(_keepAlive ? F("keep-alive") : F("close")));
456+
if (_keepAlive) {
457+
sendHeader(String(F("Keep-Alive")), String(F("timeout=")) + HTTP_MAX_CLOSE_WAIT);
458+
}
447459

448460
response += _responseHeaders;
449461
response += "\r\n";

libraries/ESP8266WebServer/src/ESP8266WebServer.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ESP8266WebServerTemplate
119119

120120
const String& uri() const { return _currentUri; }
121121
HTTPMethod method() const { return _currentMethod; }
122-
ClientType client() { return _currentClient; }
122+
ClientType& client() { return _currentClient; }
123123
HTTPUpload& upload() { return *_currentUpload; }
124124

125125
// Allows setting server options (i.e. SSL keys) by the instantiator
@@ -184,6 +184,14 @@ class ESP8266WebServerTemplate
184184
sendContent(emptyString);
185185
}
186186

187+
// Whether other requests should be accepted from the client on the
188+
// same socket after a response is sent.
189+
// This will automatically configure the "Connection" header of the response.
190+
// Defaults to true when the client's HTTP version is 1.1 or above, otherwise it defaults to false.
191+
// If the client sends the "Connection" header, the value given by the header is used.
192+
void keepAlive(bool keepAlive) { _keepAlive = keepAlive; }
193+
bool keepAlive() { return _keepAlive; }
194+
187195
static String credentialHash(const String& username, const String& realm, const String& password);
188196

189197
static String urlDecode(const String& text);
@@ -254,6 +262,7 @@ class ESP8266WebServerTemplate
254262
uint8_t _currentVersion;
255263
HTTPClientStatus _currentStatus;
256264
unsigned long _statusChange;
265+
bool _keepAlive;
257266

258267
RequestHandlerType* _currentHandler;
259268
RequestHandlerType* _firstHandler;

libraries/ESP8266WebServer/src/Parsing-impl.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ typename ESP8266WebServerTemplate<ServerType>::ClientFuture ESP8266WebServerTemp
109109
}
110110
_currentMethod = method;
111111

112-
DBGWS("method: %s url: %s search: %s\n",
113-
methodStr.c_str(), url.c_str(), searchStr.c_str());
112+
_keepAlive = _currentVersion > 0; // Keep the connection alive by default
113+
// if the protocol version is greater than HTTP 1.0
114+
115+
DBGWS("method: %s url: %s search: %s keepAlive=: %d\n",
116+
methodStr.c_str(), url.c_str(), searchStr.c_str(), _keepAlive);
114117

115118
//attach handler
116119
RequestHandlerType* handler;
@@ -133,7 +136,7 @@ typename ESP8266WebServerTemplate<ServerType>::ClientFuture ESP8266WebServerTemp
133136
while(1){
134137
req = client.readStringUntil('\r');
135138
client.readStringUntil('\n');
136-
if (req.isEmpty()) break;//no moar headers
139+
if (req.isEmpty()) break; //no more headers
137140
int headerDiv = req.indexOf(':');
138141
if (headerDiv == -1){
139142
break;
@@ -161,6 +164,8 @@ typename ESP8266WebServerTemplate<ServerType>::ClientFuture ESP8266WebServerTemp
161164
contentLength = headerValue.toInt();
162165
} else if (headerName.equalsIgnoreCase(F("Host"))){
163166
_hostHeader = headerValue;
167+
} else if (headerName.equalsIgnoreCase(F("Connection"))){
168+
_keepAlive = headerValue.equalsIgnoreCase(F("keep-alive"));
164169
}
165170
}
166171

@@ -220,6 +225,8 @@ typename ESP8266WebServerTemplate<ServerType>::ClientFuture ESP8266WebServerTemp
220225

221226
if (headerName.equalsIgnoreCase(F("Host"))){
222227
_hostHeader = headerValue;
228+
} else if (headerName.equalsIgnoreCase(F("Connection"))){
229+
_keepAlive = headerValue.equalsIgnoreCase(F("keep-alive"));
223230
}
224231
}
225232
_parseArguments(searchStr);

libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ void setup() {
148148
BearSSL::WiFiClientSecure *bear = new BearSSL::WiFiClientSecure();
149149
// Integrate the cert store with this connection
150150
bear->setCertStore(&certStore);
151-
Serial.printf("Attempting to fetch https://www.github.com/...\n");
152-
fetchURL(bear, "www.github.com", 443, "/");
151+
Serial.printf("Attempting to fetch https://github.com/...\n");
152+
fetchURL(bear, "github.com", 443, "/");
153153
delete bear;
154154
}
155155

libraries/Ethernet

Submodule Ethernet added at 75a3c37

libraries/Ethernet/README.adoc

Lines changed: 0 additions & 26 deletions
This file was deleted.

libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)