From 224614fb8de2b2ec1292a11d8b5de3e1aeff3db1 Mon Sep 17 00:00:00 2001 From: glennsky Date: Wed, 22 May 2024 22:09:25 +0200 Subject: [PATCH 1/4] add WebSocket subprotocol support (#81) added _subprotocol member variable to PsychicHandler class set the websocket subprotocol with setSubprotocol -- i.e. handler.setSubprotocol("can.binary+json.v1") (to talk to python-can-remote) in PsychicHttpServer.cpp added field supported_subprotocol to httpd_uri_t this field is in esp_http_server.h - but wasn't implemented in PsychicHttp Co-authored-by: Glenn Silver --- src/PsychicHandler.cpp | 10 +++++++++- src/PsychicHandler.h | 5 +++++ src/PsychicHttpServer.cpp | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/PsychicHandler.cpp b/src/PsychicHandler.cpp index f02971f..097b30e 100644 --- a/src/PsychicHandler.cpp +++ b/src/PsychicHandler.cpp @@ -7,7 +7,8 @@ PsychicHandler::PsychicHandler() : _password(""), _method(DIGEST_AUTH), _realm(""), - _authFailMsg("") + _authFailMsg(""), + _subprotocol("") {} PsychicHandler::~PsychicHandler() { @@ -26,6 +27,13 @@ bool PsychicHandler::filter(PsychicRequest *request){ return _filter == NULL || _filter(request); } +void PsychicHandler::setSubprotocol(const String& subprotocol) { + this->_subprotocol = subprotocol; +} +const char* PsychicHandler::getSubprotocol() const { + return _subprotocol.c_str(); +} + PsychicHandler* PsychicHandler::setAuthentication(const char *username, const char *password, HTTPAuthMethod method, const char *realm, const char *authFailMsg) { _username = String(username); _password = String(password); diff --git a/src/PsychicHandler.h b/src/PsychicHandler.h index 72d795c..bad62bf 100644 --- a/src/PsychicHandler.h +++ b/src/PsychicHandler.h @@ -24,6 +24,8 @@ class PsychicHandler { String _realm; String _authFailMsg; + String _subprotocol; + std::list _clients; public: @@ -39,6 +41,9 @@ class PsychicHandler { virtual bool isWebSocket() { return false; }; + void setSubprotocol(const String& subprotocol); + const char* getSubprotocol() const; + PsychicClient * checkForNewClient(PsychicClient *client); void checkForClosedClient(PsychicClient *client); diff --git a/src/PsychicHttpServer.cpp b/src/PsychicHttpServer.cpp index e48a73b..f318764 100644 --- a/src/PsychicHttpServer.cpp +++ b/src/PsychicHttpServer.cpp @@ -141,7 +141,8 @@ PsychicEndpoint* PsychicHttpServer::on(const char* uri, http_method method, Psyc .method = method, .handler = PsychicEndpoint::requestCallback, .user_ctx = endpoint, - .is_websocket = handler->isWebSocket() + .is_websocket = handler->isWebSocket(), + .supported_subprotocol = handler->getSubprotocol() }; // Register endpoint with ESP-IDF server From a72b15b929e0b7c39c6857e39e5e619381930080 Mon Sep 17 00:00:00 2001 From: Zach Hoeken Date: Wed, 22 May 2024 15:21:38 -0500 Subject: [PATCH 2/4] prepping for v1.1 release --- CHANGELOG.md | 3 ++- README.md | 7 +------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60c2f81..6b4e49e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,4 +13,5 @@ * PsychicHttpServerRequest -> PsychicRequest * PsychicHttpServerResponse -> PsychicResponse * PsychicHttpWebsocket.h -> PsychicWebSocket.h - * Websocket => WebSocket \ No newline at end of file + * Websocket => WebSocket +* Quite a few bugfixes from the community. \ No newline at end of file diff --git a/README.md b/README.md index 238d7b0..2ba9510 100644 --- a/README.md +++ b/README.md @@ -589,15 +589,10 @@ ArduinoMongoose is a good alternative, although the latency issues when it gets # Roadmap -## v1.1: Event Source + Handlers +## v1.2: ESPAsyncWebserver Parity -* Fix all outstanding issues on Github * Another pass over the docs * DefaultHeaders - - -## v1.2: ESPAsyncWebserver Parity - * HTTP_ANY support (by abusing httpd_req_handle_err) * Issue: it would log a warning on every request (httpd_uri.c:298) * Issue: req->user_ctx is not passed in. (httpd_uri.c:309) From 5d80dfbd4f3a5924b9a77f6c633da931023a2fa9 Mon Sep 17 00:00:00 2001 From: Zach Hoeken Date: Wed, 22 May 2024 15:25:03 -0500 Subject: [PATCH 3/4] version bump --- library.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 2eca5b1..e6f8a7a 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "PsychicHttp", - "version": "1.0.1", + "version": "1.1.0", "description": "Arduino style wrapper around ESP-IDF HTTP library. HTTP server with SSL + websockets. Works on esp32 and probably esp8266", "keywords": "network,http,https,tcp,ssl,tls,websocket,espasyncwebserver", "repository": @@ -32,7 +32,7 @@ { "owner": "bblanchon", "name": "ArduinoJson", - "version": "^6.21.4" + "version": "^7.0.4" }, { "owner": "bblanchon", From b4d54fbf9a9707ad363512c3f173e56495984c73 Mon Sep 17 00:00:00 2001 From: Zach Hoeken Date: Wed, 22 May 2024 15:29:45 -0500 Subject: [PATCH 4/4] missed arduino version bump --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 8557da1..d2b104e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PsychicHttp -version=1.0.1 +version=1.1.0 author=Zach Hoeken maintainer=Zach Hoeken sentence=PsychicHttp is a robust webserver that supports http/https + websockets.