2024-01-27 09:56:20 +01:00
# ESP Async WebServer
2020-08-21 12:41:37 +02:00
2024-01-27 09:56:20 +01:00
[![License: LGPL 3.0 ](https://img.shields.io/badge/License-LGPL%203.0-yellow.svg )](https://opensource.org/license/lgpl-3-0/)
[![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)
2020-08-21 12:43:46 +02:00
2024-05-14 13:21:01 +02:00
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.
2020-08-21 12:43:46 +02:00
2024-05-14 13:21:01 +02:00
This fork is based on [yubox-node-org/ESPAsyncWebServer ](https://github.com/yubox-node-org/ESPAsyncWebServer ) and includes all the concurrency fixes.
2020-08-21 12:43:46 +02:00
2024-02-06 17:39:53 +01:00
## Changes in this fork
2020-08-21 12:43:46 +02:00
2024-02-06 17:39:53 +01:00
- Removed SPIFFSEditor
2024-01-27 09:56:20 +01:00
- Deployed in PlatformIO registry and Arduino IDE library manager
- CI
2024-02-06 17:39:53 +01:00
- 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`
2024-05-14 13:21:01 +02:00
- 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.
2024-02-06 17:39:53 +01:00
- `WS_MAX_QUEUED_MESSAGES` : control the maximum number of messages that can be queued for a Websocket client
2024-01-27 09:56:20 +01:00
- Resurrected `AsyncWebSocketMessageBuffer` and `makeBuffer()` in order to make the fork API-compatible with the original library from me-no-dev regarding WebSocket.
2024-05-14 13:21:01 +02:00
- [#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
2020-08-21 12:43:46 +02:00
2024-01-27 09:56:20 +01:00
## Documentation
2020-08-21 12:43:46 +02:00
2024-01-27 09:56:20 +01:00
Usage and API stays the same as the original library.
Please look at the original libraries for more examples and documentation.
2020-08-21 12:43:46 +02:00
2024-01-27 09:56:20 +01:00
[https://github.com/yubox-node-org/ESPAsyncWebServer ](https://github.com/yubox-node-org/ESPAsyncWebServer )
2020-08-21 12:43:46 +02:00
2024-01-27 09:56:20 +01:00
## `AsyncWebSocketMessageBuffer` and `makeBuffer()`
2020-08-21 12:43:46 +02:00
2024-01-27 09:56:20 +01:00
The fork from `yubox-node-org` introduces some breaking API changes compared to the original library, especially regarding the use of `std::shared_ptr<std::vector<uint8_t>>` for WebSocket.
2020-08-21 12:43:46 +02:00
2024-01-27 09:56:20 +01:00
This fork is compatible with the original library from `me-no-dev` regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class.
So you have the choice of which API to use.
I strongly suggest to use the optimized API from `yubox-node-org` as it is much more efficient.
2020-08-21 12:43:46 +02:00
2024-01-27 09:56:20 +01:00
Here is an example for serializing a Json document in a websocket message buffer. This code is compatible with any forks, but not optimized:
2020-08-21 12:43:46 +02:00
```cpp
2024-01-27 09:56:20 +01:00
void send(JsonDocument& doc) {
const size_t len = measureJson(doc);
2024-02-06 17:39:53 +01:00
2024-01-27 09:56:20 +01:00
// original API from me-no-dev
AsyncWebSocketMessageBuffer* buffer = _ws->makeBuffer(len);
assert(buffer); // up to you to keep or remove this
serializeJson(doc, buffer->get(), len);
_ws->textAll(buffer);
2020-08-21 12:43:46 +02:00
}
```
2024-01-27 09:56:20 +01:00
Here is an example for serializing a Json document in a more optimized way, and compatible with both forks:
2020-08-21 12:43:46 +02:00
```cpp
2024-01-27 09:56:20 +01:00
void send(JsonDocument& doc) {
const size_t len = measureJson(doc);
2020-08-21 12:43:46 +02:00
2024-01-27 09:56:20 +01:00
#if defined(ASYNCWEBSERVER_FORK_mathieucarbou)
2020-08-21 12:43:46 +02:00
2024-01-27 09:56:20 +01:00
// this fork (originally from yubox-node-org), uses another API with shared pointer that better support concurrent use cases then the original project
auto buffer = std::make_shared< std::vector < uint8_t > >(len);
assert(buffer); // up to you to keep or remove this
serializeJson(doc, buffer->data(), len);
_ws->textAll(std::move(buffer));
2020-08-21 12:43:46 +02:00
2024-01-27 09:56:20 +01:00
#else
2020-08-21 12:43:46 +02:00
2024-01-27 09:56:20 +01:00
// original API from me-no-dev
AsyncWebSocketMessageBuffer* buffer = _ws->makeBuffer(len);
assert(buffer); // up to you to keep or remove this
serializeJson(doc, buffer->get(), len);
_ws->textAll(buffer);
2020-08-21 12:43:46 +02:00
2024-01-27 09:56:20 +01:00
#endif
2020-08-21 12:43:46 +02:00
}
```