Skip to content

Commit 334959e

Browse files
committed
Merge branch 'lorol-master' into yuboxfixes
2 parents e0bb829 + 6a67b1a commit 334959e

File tree

131 files changed

+16415
-1622
lines changed

Some content is hidden

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

131 files changed

+16415
-1622
lines changed

.github/scripts/on-push.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if [ ! -z "$TRAVIS_BUILD_DIR" ]; then
77
export GITHUB_REPOSITORY="$TRAVIS_REPO_SLUG"
88
elif [ -z "$GITHUB_WORKSPACE" ]; then
99
export GITHUB_WORKSPACE="$PWD"
10-
export GITHUB_REPOSITORY="me-no-dev/ESPAsyncWebServer"
10+
export GITHUB_REPOSITORY="lorol/ESPAsyncWebServer"
1111
fi
1212

1313
TARGET_PLATFORM="$1"
@@ -34,8 +34,12 @@ if [ "$BUILD_PIO" -eq 0 ]; then
3434
cp -rf "$GITHUB_WORKSPACE" "$ARDUINO_USR_PATH/libraries/ESPAsyncWebServer"
3535
echo "Installing ArduinoJson ..."
3636
git clone https://github.com/bblanchon/ArduinoJson "$ARDUINO_USR_PATH/libraries/ArduinoJson" > /dev/null 2>&1
37+
echo "Installing DHT sensor library ..."
38+
git clone https://github.com/adafruit/DHT-sensor-library "$ARDUINO_USR_PATH/libraries/DHT-sensor-library" > /dev/null 2>&1
3739

3840
if [[ "$TARGET_PLATFORM" == "esp32" ]]; then
41+
echo "Installing LITTLEFS for ESP32 ..."
42+
git clone https://github.com/lorol/LITTLEFS "$ARDUINO_USR_PATH/libraries/LITTLEFS" > /dev/null 2>&1
3943
echo "Installing AsyncTCP ..."
4044
git clone https://github.com/me-no-dev/AsyncTCP "$ARDUINO_USR_PATH/libraries/AsyncTCP" > /dev/null 2>&1
4145
FQBN="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app"

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# In this fork
2+
- SPIFFSEditor modifications
3+
- Added [extras](https://github.com/lorol/ESPAsyncWebServer/tree/master/extras) folder with (Win) tools for re-packing, editing, updating and compressing html to binary arrays embedded to source
4+
- Added a [SmartSwitch](https://github.com/lorol/ESPAsyncWebServer/tree/master/examples/SmartSwitch) example to test code features
5+
- Applied the memory optimizations from [sascha432](https://github.com/sascha432/ESPAsyncWebServer) fork
6+
- Cookie Authentication including on Websocket part, based on [ayushsharma82](https://github.com/me-no-dev/ESPAsyncWebServer/pull/684) PR, new functions added:
7+
- For Websocket: ```void handleHandshake(AwsHandshakeHandler handler) ```
8+
- For EventSource: ```void authorizeConnect(ArAuthorizeConnectHandler cb)```
9+
- [Additions to this README.md from jendakol' PR](https://github.com/me-no-dev/ESPAsyncWebServer/pull/770)
10+
- [Respond with file content using a callback and extra headers](#respond-with-file-content-using-a-callback-and-extra-headers)
11+
- [Serving static files by custom handling](#serving-static-files-by-custom-handling)
12+
- Added LittleFS choice for both [esp8266](https://github.com/esp8266/Arduino/tree/master/libraries/LittleFS) / [esp32](https://github.com/lorol/LITTLEFS) , and FatFS tests for esp32 see [SmartSwitch](https://github.com/lorol/ESPAsyncWebServer/blob/master/examples/SmartSwitch/SmartSwitch.ino#L16 )
13+
------------------------------------------------------------------------------------------
14+
115
# ESPAsyncWebServer
216
[![Build Status](https://travis-ci.org/me-no-dev/ESPAsyncWebServer.svg?branch=master)](https://travis-ci.org/me-no-dev/ESPAsyncWebServer) ![](https://github.com/me-no-dev/ESPAsyncWebServer/workflows/ESP%20Async%20Web%20Server%20CI/badge.svg) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/395dd42cfc674e6ca2e326af3af80ffc)](https://www.codacy.com/manual/me-no-dev/ESPAsyncWebServer?utm_source=github.com&utm_medium=referral&utm_content=me-no-dev/ESPAsyncWebServer&utm_campaign=Badge_Grade)
317

@@ -53,6 +67,7 @@ To use this library you might need to have the latest git versions of [ESP32](ht
5367
- [Respond with content coming from a File containing templates](#respond-with-content-coming-from-a-file-containing-templates)
5468
- [Respond with content using a callback](#respond-with-content-using-a-callback)
5569
- [Respond with content using a callback and extra headers](#respond-with-content-using-a-callback-and-extra-headers)
70+
- [Respond with file content using a callback and extra headers](#respond-with-file-content-using-a-callback-and-extra-headers)
5671
- [Respond with content using a callback containing templates](#respond-with-content-using-a-callback-containing-templates)
5772
- [Respond with content using a callback containing templates and extra headers](#respond-with-content-using-a-callback-containing-templates-and-extra-headers)
5873
- [Chunked Response](#chunked-response)
@@ -67,6 +82,7 @@ To use this library you might need to have the latest git versions of [ESP32](ht
6782
- [Specifying Cache-Control header](#specifying-cache-control-header)
6883
- [Specifying Date-Modified header](#specifying-date-modified-header)
6984
- [Specifying Template Processor callback](#specifying-template-processor-callback)
85+
- [Serving static files by custom handling](#serving-static-files-by-custom-handling)
7086
- [Param Rewrite With Matching](#param-rewrite-with-matching)
7187
- [Using filters](#using-filters)
7288
- [Serve different site files in AP mode](#serve-different-site-files-in-ap-mode)
@@ -602,6 +618,43 @@ response->addHeader("Server","ESP Async Web Server");
602618
request->send(response);
603619
```
604620
621+
### Respond with file content using a callback and extra headers
622+
623+
With this code your ESP is able to serve even large (large in terms of ESP, e.g. 100kB) files
624+
without memory problems.
625+
626+
You need to create a file handler in outer function (to have a single one for request) but use
627+
it in a lambda. The catch is that the lambda has it's own lifecycle which may/will cause it's
628+
called after the original function is over thus the original file handle is destroyed. Using the
629+
captured `&file` in the lambda then causes segfault (Hello, Exception 9!) and the whole ESP crashes.
630+
By using this code, you tell the compiler to move the handle into the lambda so it won't be
631+
destroyed when outer function (that one where you call `request->send(response)`) ends.
632+
633+
```cpp
634+
const File file = ... // e.g. SPIFFS.open(path, "r");
635+
636+
const contentType = "application/javascript";
637+
638+
AsyncWebServerResponse *response = request->beginResponse(
639+
contentType,
640+
file.size(),
641+
[file](uint8_t *buffer, size_t maxLen, size_t total) mutable -> size_t {
642+
int bytes = file.read(buffer, maxLen);
643+
644+
// close file at the end
645+
if (bytes + total == file.size()) file.close();
646+
647+
return max(0, bytes); // return 0 even when no bytes were loaded
648+
}
649+
);
650+
651+
if (gzipped) {
652+
response->addHeader(F("Content-Encoding"), F("gzip"));
653+
}
654+
655+
request->send(response);
656+
```
657+
605658
### Respond with content using a callback containing templates
606659
```cpp
607660
String processor(const String& var)
@@ -858,6 +911,53 @@ String processor(const String& var)
858911
server.serveStatic("/", SPIFFS, "/www/").setTemplateProcessor(processor);
859912
```
860913
914+
### Serving static files by custom handling
915+
916+
It may happen your static files are too big and the ESP will crash the request before it sends the whole file.
917+
In that case, you can handle static files with custom file serving through not found handler.
918+
919+
This code below is more-or-less equivalent to this:
920+
```cpp
921+
webServer.serveStatic("/", SPIFFS, STATIC_FILES_PREFIX).setDefaultFile("index.html")
922+
```
923+
924+
First, declare the handling function:
925+
```cpp
926+
bool handleStaticFile(AsyncWebServerRequest *request) {
927+
String path = STATIC_FILES_PREFIX + request->url();
928+
929+
if (path.endsWith("/")) path += F("index.html");
930+
931+
String contentType = getContentType(path);
932+
String pathWithGz = path + ".gz";
933+
934+
if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
935+
bool gzipped = false;
936+
if (SPIFFS.exists(pathWithGz)) {
937+
gzipped = true;
938+
path += ".gz";
939+
}
940+
941+
// TODO serve the file
942+
943+
return true;
944+
}
945+
946+
return false;
947+
}
948+
```
949+
And then configure your webserver:
950+
```cpp
951+
webServer.onNotFound([](AsyncWebServerRequest *request) {
952+
if (handleStaticFile(request)) return;
953+
954+
request->send(404);
955+
});
956+
```
957+
958+
You may want to try [Respond with file content using a callback and extra headers](#respond-with-file-content-using-a-callback-and-extra-headers)
959+
For actual serving the file.
960+
861961
## Param Rewrite With Matching
862962
It is possible to rewrite the request url with parameter matchg. Here is an example with one parameter:
863963
Rewrite for example "/radio/{frequence}" -> "/radio?f={frequence}"

0 commit comments

Comments
 (0)