From e2bc8b4dc8cfaf2680c3a309d187ed5448d02b6e Mon Sep 17 00:00:00 2001 From: Pablo2048 Date: Tue, 14 May 2024 13:21:01 +0200 Subject: [PATCH] Verze 2.9.5 odsud https://github.com/mathieucarbou/ESPAsyncWebServer/releases/tag/v2.9.5 --- README.md | 13 ++++--- docs/_config.yml | 4 +-- docs/index.md | 13 ++++--- examples/CaptivePortal/CaptivePortal.ino | 11 ++++-- library.json_ | 11 +++--- library.properties | 4 +-- platformio.ini | 45 ++++++++++++++++-------- src/AsyncEventSource.cpp | 3 ++ src/AsyncJson.h | 23 ++++++++---- src/AsyncWebSocket.cpp | 9 +++-- src/ESPAsyncWebServer.h | 6 ++-- src/WebAuthentication.cpp | 6 ++++ src/WebResponses.cpp | 4 +-- 13 files changed, 105 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 3c23491..ee7bb05 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,10 @@ [![Continuous Integration](https://github.com/mathieucarbou/ESPAsyncWebServer/actions/workflows/ci.yml/badge.svg)](https://github.com/mathieucarbou/ESPAsyncWebServer/actions/workflows/ci.yml) [![PlatformIO Registry](https://badges.registry.platformio.org/packages/mathieucarbou/library/ESP%20Async%20WebServer.svg)](https://registry.platformio.org/libraries/mathieucarbou/ESP%20Async%20WebServer) -Async Web Server for ESP31B +Asynchronous HTTP and WebSocket Server Library for ESP32. +Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc. -This fork is based on https://github.com/yubox-node-org/ESPAsyncWebServer and includes all the concurrency fixes. +This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubox-node-org/ESPAsyncWebServer) and includes all the concurrency fixes. ## Changes in this fork @@ -16,10 +17,14 @@ This fork is based on https://github.com/yubox-node-org/ESPAsyncWebServer and in - Some code cleanup - `SSE_MAX_QUEUED_MESSAGES` to control the maximum number of messages that can be queued for a SSE client - `write()` function public in `AsyncEventSource.h` -- Arduino Json 7 compatibility and by default, still compatible with 6 (`AsyncJson.h`) +- Arduino Json 7 compatibility and backward compatible with 6 and 6 (changes in `AsyncJson.h`). The API to use Json has not changed. These are only internal changes. - `WS_MAX_QUEUED_MESSAGES`: control the maximum number of messages that can be queued for a Websocket client - Resurrected `AsyncWebSocketMessageBuffer` and `makeBuffer()` in order to make the fork API-compatible with the original library from me-no-dev regarding WebSocket. -- [#5](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/5): set real "Last-Modified" header based on file's LastWrite time ([@vortigont](https://github.com/vortigont)) +- [#5](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/5) ([@vortigont](https://github.com/vortigont)): set real "Last-Modified" header based on file's LastWrite time +- [#13](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/13) ([@tueddy](https://github.com/tueddy)): Compile with Arduino 3 (ESP-IDF 5.1) +- [#14](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/14) ([@nilo85](https://github.com/nilo85)): Add support for Auth & GET requests in AsyncCallbackJsonWebHandler +- Depends on `mathieucarbou/Async TCP @ ^3.1.2` +- Arduino 3 / ESP-IDF 5.1 compatibility ## Documentation diff --git a/docs/_config.yml b/docs/_config.yml index 4750b09..532070b 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,7 +1,7 @@ # bundle exec jekyll serve --host=0.0.0.0 -title: Asynchronous HTTP and WebSocket Server Library for ESP32 -description: "Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc" +title: ESP Async WebServer +description: "Asynchronous HTTP and WebSocket Server Library for ESP32" remote_theme: pages-themes/cayman@v0.2.0 plugins: - jekyll-remote-theme diff --git a/docs/index.md b/docs/index.md index 3c23491..ee7bb05 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,9 +4,10 @@ [![Continuous Integration](https://github.com/mathieucarbou/ESPAsyncWebServer/actions/workflows/ci.yml/badge.svg)](https://github.com/mathieucarbou/ESPAsyncWebServer/actions/workflows/ci.yml) [![PlatformIO Registry](https://badges.registry.platformio.org/packages/mathieucarbou/library/ESP%20Async%20WebServer.svg)](https://registry.platformio.org/libraries/mathieucarbou/ESP%20Async%20WebServer) -Async Web Server for ESP31B +Asynchronous HTTP and WebSocket Server Library for ESP32. +Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc. -This fork is based on https://github.com/yubox-node-org/ESPAsyncWebServer and includes all the concurrency fixes. +This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubox-node-org/ESPAsyncWebServer) and includes all the concurrency fixes. ## Changes in this fork @@ -16,10 +17,14 @@ This fork is based on https://github.com/yubox-node-org/ESPAsyncWebServer and in - Some code cleanup - `SSE_MAX_QUEUED_MESSAGES` to control the maximum number of messages that can be queued for a SSE client - `write()` function public in `AsyncEventSource.h` -- Arduino Json 7 compatibility and by default, still compatible with 6 (`AsyncJson.h`) +- Arduino Json 7 compatibility and backward compatible with 6 and 6 (changes in `AsyncJson.h`). The API to use Json has not changed. These are only internal changes. - `WS_MAX_QUEUED_MESSAGES`: control the maximum number of messages that can be queued for a Websocket client - Resurrected `AsyncWebSocketMessageBuffer` and `makeBuffer()` in order to make the fork API-compatible with the original library from me-no-dev regarding WebSocket. -- [#5](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/5): set real "Last-Modified" header based on file's LastWrite time ([@vortigont](https://github.com/vortigont)) +- [#5](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/5) ([@vortigont](https://github.com/vortigont)): set real "Last-Modified" header based on file's LastWrite time +- [#13](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/13) ([@tueddy](https://github.com/tueddy)): Compile with Arduino 3 (ESP-IDF 5.1) +- [#14](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/14) ([@nilo85](https://github.com/nilo85)): Add support for Auth & GET requests in AsyncCallbackJsonWebHandler +- Depends on `mathieucarbou/Async TCP @ ^3.1.2` +- Arduino 3 / ESP-IDF 5.1 compatibility ## Documentation diff --git a/examples/CaptivePortal/CaptivePortal.ino b/examples/CaptivePortal/CaptivePortal.ino index f97f142..5681709 100644 --- a/examples/CaptivePortal/CaptivePortal.ino +++ b/examples/CaptivePortal/CaptivePortal.ino @@ -34,8 +34,15 @@ public: void setup(){ - //your other setup stuff... - WiFi.softAP("esp-captive"); + Serial.begin(115200); + Serial.println(); + Serial.println("Configuring access point..."); + + if (!WiFi.softAP("esp-captive")) { + Serial.println("Soft AP creation failed."); + while (1); + } + dnsServer.start(53, "*", WiFi.softAPIP()); server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER);//only when requested from AP //more handlers... diff --git a/library.json_ b/library.json_ index 526a454..9d18cf4 100644 --- a/library.json_ +++ b/library.json_ @@ -1,6 +1,6 @@ { "name": "ESP Async WebServer", - "version": "2.7.0", + "version": "2.9.5", "description": "Asynchronous HTTP and WebSocket Server Library for ESP32. Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc.", "keywords": "http,async,websocket,webserver", "homepage": "https://github.com/mathieucarbou/ESPAsyncWebServer", @@ -20,13 +20,14 @@ "license": "LGPL-3.0", "frameworks": "arduino", "platforms": [ - "espressif32" + "espressif32", + "espressif8266" ], "dependencies": [ { - "owner": "esphome", - "name": "AsyncTCP-esphome", - "version": "^2.1.1", + "owner": "mathieucarbou", + "name": "Async TCP", + "version": "^3.1.2", "platforms": "espressif32" }, { diff --git a/library.properties b/library.properties index a0bd50d..7d38349 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=ESP Async WebServer -version=2.7.0 +version=2.9.5 author=Me-No-Dev maintainer=Mathieu Carbou sentence=Asynchronous HTTP and WebSocket Server Library for ESP32 paragraph=Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc category=Other url=https://github.com/mathieucarbou/ESPAsyncWebServer -architectures=esp32 +architectures=* license=LGPL-3.0 diff --git a/platformio.ini b/platformio.ini index fdd5074..0bcd99e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,31 +1,46 @@ [env] framework = arduino - -build_flags = -Wall -Wextra - +build_flags = + -Wall -Wextra + -D CONFIG_ARDUHAL_LOG_COLORS + -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG +lib_deps = + bblanchon/ArduinoJson @ 7.0.4 + mathieucarbou/Async TCP @ ^3.1.2 upload_protocol = esptool -upload_port = /dev/cu.usbserial-0001 - -monitor_port = /dev/cu.usbserial-0001 monitor_speed = 115200 monitor_filters = esp32_exception_decoder, log2file [platformio] -default_envs = esp8266 lib_dir = . -; src_dir = examples/CaptivePortal -src_dir = examples/SimpleServer +src_dir = examples/CaptivePortal +; src_dir = examples/SimpleServer -[env:esp32] -platform = espressif32 +[env:v660] +platform = espressif32@6.6.0 +board = esp32dev + +[env:latest-espressif32] +platform = https://github.com/platformio/platform-espressif32.git +board = esp32dev + +[env:latest-arduino] +platform = espressif32 +platform_packages= + platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#master + platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-libs.git#idf-release/v5.1 +board = esp32dev + +[env:v300-rc1] +platform = espressif32 +platform_packages= + platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.0-rc1 + platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-libs.git#idf-release/v5.1 board = esp32dev -lib_deps = - bblanchon/ArduinoJson @ 7.0.2 - esphome/AsyncTCP-esphome @ 2.1.1 [env:esp8266] platform = espressif8266 board = huzzah lib_deps = - bblanchon/ArduinoJson @ 7.0.2 + bblanchon/ArduinoJson @ 7.0.4 esphome/ESPAsyncTCP-esphome @ 2.0.0 diff --git a/src/AsyncEventSource.cpp b/src/AsyncEventSource.cpp index fdafb1b..1c34c85 100644 --- a/src/AsyncEventSource.cpp +++ b/src/AsyncEventSource.cpp @@ -19,6 +19,9 @@ */ #include "Arduino.h" #include "AsyncEventSource.h" +#ifndef ESP8266 + #include +#endif static String generateEventMessage(const char *message, const char *event, uint32_t id, uint32_t reconnect){ String ev; diff --git a/src/AsyncJson.h b/src/AsyncJson.h index f4e99d1..b2f6e2e 100644 --- a/src/AsyncJson.h +++ b/src/AsyncJson.h @@ -137,7 +137,11 @@ class AsyncJsonResponse : public AsyncAbstractResponse { return _contentLength; } - size_t getSize() { return _jsonBuffer.size(); } + size_t getSize() const { return _jsonBuffer.size(); } + +#if ARDUINOJSON_VERSION_MAJOR >= 6 + bool overflowed() const { return _jsonBuffer.overflowed(); } +#endif size_t _fillBuffer(uint8_t* data, size_t len) { ChunkPrint dest(data, _sentLength, len); @@ -197,10 +201,10 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler { public: #if ARDUINOJSON_VERSION_MAJOR == 6 AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) - : _uri(uri), _method(HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize), _maxContentLength(16384) {} + : _uri(uri), _method(HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize), _maxContentLength(16384) {} #else AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest) - : _uri(uri), _method(HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384) {} + : _uri(uri), _method(HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384) {} #endif void setMethod(WebRequestMethodComposite method) { _method = method; } @@ -211,13 +215,14 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler { if (!_onRequest) return false; - if (!(_method & request->method())) + WebRequestMethodComposite request_method = request->method(); + if (!(_method & request_method)) return false; if (_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri + "/"))) return false; - if (!request->contentType().equalsIgnoreCase(JSON_MIMETYPE)) + if (request_method != HTTP_GET && !request->contentType().equalsIgnoreCase(JSON_MIMETYPE)) return false; request->addInterestingHeader("ANY"); @@ -225,8 +230,14 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler { } virtual void handleRequest(AsyncWebServerRequest* request) override final { + if((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str())) + return request->requestAuthentication(); if (_onRequest) { - if (request->_tempObject != NULL) { + if (request->method() == HTTP_GET) { + JsonVariant json; + _onRequest(request, json); + return; + } else if (request->_tempObject != NULL) { #if ARDUINOJSON_VERSION_MAJOR == 5 DynamicJsonBuffer jsonBuffer; diff --git a/src/AsyncWebSocket.cpp b/src/AsyncWebSocket.cpp index d654cd1..594ffb5 100644 --- a/src/AsyncWebSocket.cpp +++ b/src/AsyncWebSocket.cpp @@ -27,6 +27,7 @@ #ifndef ESP8266 #include "mbedtls/sha1.h" +#include #else #include #endif @@ -212,8 +213,6 @@ public: uint8_t opcode(){ return _opcode; } uint8_t len(){ return _len + 2; } size_t send(AsyncClient *client){ - if (_finished) - return 0; // fix from https://github.com/me-no-dev/ESPAsyncWebServer/pull/1390/files _finished = true; return webSocketSendFrame(client, true, _opcode & 0x0F, _mask, _data, _len); } @@ -1274,9 +1273,15 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket (String&)key += WS_STR_UUID; mbedtls_sha1_context ctx; mbedtls_sha1_init(&ctx); +#if ESP_IDF_VERSION_MAJOR == 5 + mbedtls_sha1_starts(&ctx); + mbedtls_sha1_update(&ctx, (const unsigned char*)key.c_str(), key.length()); + mbedtls_sha1_finish(&ctx, hash); +#else mbedtls_sha1_starts_ret(&ctx); mbedtls_sha1_update_ret(&ctx, (const unsigned char*)key.c_str(), key.length()); mbedtls_sha1_finish_ret(&ctx, hash); +#endif mbedtls_sha1_free(&ctx); #endif base64_encodestate _state; diff --git a/src/ESPAsyncWebServer.h b/src/ESPAsyncWebServer.h index bd3a41b..ba3841a 100644 --- a/src/ESPAsyncWebServer.h +++ b/src/ESPAsyncWebServer.h @@ -40,10 +40,10 @@ #error Platform not supported #endif -#define ASYNCWEBSERVER_VERSION "2.7.0" +#define ASYNCWEBSERVER_VERSION "2.9.5" #define ASYNCWEBSERVER_VERSION_MAJOR 2 -#define ASYNCWEBSERVER_VERSION_MINOR 7 -#define ASYNCWEBSERVER_VERSION_REVISION 0 +#define ASYNCWEBSERVER_VERSION_MINOR 9 +#define ASYNCWEBSERVER_VERSION_REVISION 5 #define ASYNCWEBSERVER_FORK_mathieucarbou #ifdef ASYNCWEBSERVER_REGEX diff --git a/src/WebAuthentication.cpp b/src/WebAuthentication.cpp index 1a22afd..2f122d7 100644 --- a/src/WebAuthentication.cpp +++ b/src/WebAuthentication.cpp @@ -77,9 +77,15 @@ static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or mo memset(_buf, 0x00, 16); #ifdef ESP32 mbedtls_md5_init(&_ctx); +#if ESP_IDF_VERSION_MAJOR == 5 + mbedtls_md5_starts(&_ctx); + mbedtls_md5_update(&_ctx, data, len); + mbedtls_md5_finish(&_ctx, _buf); +#else mbedtls_md5_starts_ret(&_ctx); mbedtls_md5_update_ret(&_ctx, data, len); mbedtls_md5_finish_ret(&_ctx, _buf); +#endif #else MD5Init(&_ctx); MD5Update(&_ctx, data, len); diff --git a/src/WebResponses.cpp b/src/WebResponses.cpp index 22a549f..a783de0 100644 --- a/src/WebResponses.cpp +++ b/src/WebResponses.cpp @@ -539,7 +539,7 @@ AsyncFileResponse::AsyncFileResponse(FS &fs, const String& path, const String& c snprintf_P(buf, sizeof (buf), PSTR("attachment; filename=\"%s\""), filename); } else { // set filename and force rendering - snprintf_P(buf, sizeof (buf), PSTR("inline; filename=\"%s\""), filename); + snprintf_P(buf, sizeof (buf), PSTR("inline")); } addHeader(F("Content-Disposition"), buf); } @@ -570,7 +570,7 @@ AsyncFileResponse::AsyncFileResponse(File content, const String& path, const Str if(download) { snprintf_P(buf, sizeof (buf), PSTR("attachment; filename=\"%s\""), filename); } else { - snprintf_P(buf, sizeof (buf), PSTR("inline; filename=\"%s\""), filename); + snprintf_P(buf, sizeof (buf), PSTR("inline")); } addHeader(F("Content-Disposition"), buf); }