From e2b1ba25139e40211fd6c183a750c6dd3d95e25a Mon Sep 17 00:00:00 2001 From: Francesco Stefanni Date: Wed, 24 Nov 2021 08:20:46 +0100 Subject: [PATCH 1/2] Fixed compiling with ESP32 --- src/HTTPConnection.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/HTTPConnection.hpp b/src/HTTPConnection.hpp index fb15d7a..f3a3375 100644 --- a/src/HTTPConnection.hpp +++ b/src/HTTPConnection.hpp @@ -6,7 +6,11 @@ #include #include +#ifdef ESP32 +#include +#else #include +#endif #include // Required for sockets From 86bba434b5050df06167a7ba0d004b78e21bc439 Mon Sep 17 00:00:00 2001 From: Francesco Stefanni Date: Fri, 3 Dec 2021 17:45:52 +0100 Subject: [PATCH 2/2] Fixed management of Connection header --- src/HTTPConnection.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/HTTPConnection.cpp b/src/HTTPConnection.cpp index 0ab739c..9c9ad99 100644 --- a/src/HTTPConnection.cpp +++ b/src/HTTPConnection.cpp @@ -14,7 +14,7 @@ HTTPConnection::HTTPConnection(ResourceResolver * resResolver): _clientState = CSTATE_UNDEFINED; _httpHeaders = NULL; _defaultHeaders = NULL; - _isKeepAlive = false; + _isKeepAlive = true; _lastTransmissionTS = millis(); _shutdownTS = 0; _wsHandler = nullptr; @@ -44,9 +44,9 @@ int HTTPConnection::initialize(int serverSocketID, HTTPHeaders *defaultHeaders) refreshTimeout(); return _socket; } - + HTTPS_LOGE("Could not accept() new connection"); - + _addrLen = 0; _connectionState = STATE_ERROR; _clientState = CSTATE_ACTIVE; @@ -452,15 +452,15 @@ void HTTPConnection::loop() { [](unsigned char c){ return ::tolower(c); } ); } - if (std::string("keep-alive").compare(connectionHeaderValue)==0) { - HTTPS_LOGD("Keep-Alive activated. FID=%d", _socket); - _isKeepAlive = true; - } else { + if (std::string("close").compare(connectionHeaderValue)==0) { HTTPS_LOGD("Keep-Alive disabled. FID=%d", _socket); _isKeepAlive = false; + } else { + HTTPS_LOGD("Keep-Alive activated. FID=%d", _socket); + _isKeepAlive = true; } } else { - _isKeepAlive = false; + _isKeepAlive = true; } // Create request context @@ -520,7 +520,7 @@ void HTTPConnection::loop() { // Finally, after the handshake is done, we create the WebsocketHandler and change the internal state. if(websocketRequested) { _wsHandler = ((WebsocketNode*)resolvedResource.getMatchingNode())->newHandler(); - _wsHandler->initialize(this); // make websocket with this connection + _wsHandler->initialize(this); // make websocket with this connection _connectionState = STATE_WEBSOCKET; } else { // Handling the request is done @@ -680,7 +680,7 @@ std::string websocketKeyResponseHash(std::string const &key) { (const unsigned char*)shaData, HTTPS_SHA1_LENGTH ); - + // Check result and return the encoded string if (res != 0) { return std::string();