diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..a0498d9 --- /dev/null +++ b/.clang-format @@ -0,0 +1,16 @@ +Language: Cpp +BasedOnStyle: LLVM + +AccessModifierOffset: -2 +AllowShortIfStatementsOnASingleLine: false +ColumnLimit: 0 +ContinuationIndentWidth: 2 +FixNamespaceComments: false +IndentAccessModifiers: true +IndentCaseLabels: true +IndentWidth: 2 +NamespaceIndentation: All +PointerAlignment: Left +ReferenceAlignment: Left +TabWidth: 2 +UseTab: Never \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..e411f9b --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,13 @@ +# These are supported funding model platforms + +github: mathieucarbou +# patreon: # Replace with a single Patreon username +# open_collective: # Replace with a single Open Collective username +# ko_fi: # Replace with a single Ko-fi username +# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +# liberapay: # Replace with a single Liberapay username +# issuehunt: # Replace with a single IssueHunt username +# otechie: # Replace with a single Otechie username +# lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +custom: https://paypal.me/mathieucarboufr diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..bd654c2 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,20 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "gitsubmodule" + directory: "/" + schedule: + interval: "daily" + reviewers: + - "mathieucarbou" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + reviewers: + - "mathieucarbou" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3c2a08c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,92 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json + +name: Continuous Integration + +on: + workflow_dispatch: + push: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + arduino: + name: Arduino + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - core: esp32:esp32 + board: esp32:esp32:esp32 + eeprom: true + softwareserial: false + index_url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install arduino-cli + run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh + + - name: Update core index + run: arduino-cli core update-index --additional-urls "${{ matrix.index_url }}" + + - name: Install core + run: arduino-cli core install --additional-urls "${{ matrix.index_url }}" ${{ matrix.core }} + + - name: Install ArduinoJson + run: arduino-cli lib install ArduinoJson@7.0.2 + + - name: Install AsyncTCP-esphome + run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/esphome-AsyncTCP#v2.1.1 + + - name: Build CaptivePortal + run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/CaptivePortal/CaptivePortal.ino" + + - name: Build SimpleServer + run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/SimpleServer/SimpleServer.ino" + + platformio: + name: PlatformIO + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - platform: espressif32 + board: esp32dev + eeprom: true + softwareserial: false + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up cache + uses: actions/cache@v4 + with: + path: | + ~/.platformio + ~/.cache/pip + key: ${{ runner.os }}-platformio + + - name: Set up Python 3.x + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install PlatformIO + run: pip install platformio + + - name: Install platform "${{ matrix.platform }}" + run: platformio platform install ${{ matrix.platform }} + + - name: Build CaptivePortal + run: platformio ci "examples/CaptivePortal/CaptivePortal.ino" -l '.' -b ${{ matrix.board }} + + - name: Build SimpleServer + run: platformio ci "examples/SimpleServer/SimpleServer.ino" -l '.' -b ${{ matrix.board }} diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml new file mode 100644 index 0000000..da098fd --- /dev/null +++ b/.github/workflows/dependabot.yml @@ -0,0 +1,19 @@ +name: PlatformIO Dependabot + +on: + workflow_dispatch: + schedule: + # Runs every day at 01:00 + - cron: "0 1 * * *" + +jobs: + dependabot: + runs-on: ubuntu-latest + name: PlatformIO Dependabot + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: run PlatformIO Dependabot + uses: peterus/platformio_dependabot@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index a0f0e53..4ac15a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ -.vscode .DS_Store +.lh +/.pio +/.vscode/* +!/.vscode/settings.json +/logs diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e1b7035..0000000 --- a/.travis.yml +++ /dev/null @@ -1,46 +0,0 @@ -sudo: false - -language: python - -os: - - linux - -git: - depth: false - -stages: - - build - -jobs: - include: - - - name: "Build Arduino ESP32" - if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) - stage: build - script: bash $TRAVIS_BUILD_DIR/.github/scripts/on-push.sh esp32 - - - name: "Build Arduino ESP8266" - if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) - stage: build - script: bash $TRAVIS_BUILD_DIR/.github/scripts/on-push.sh esp8266 - - - name: "Build Platformio ESP32" - if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) - stage: build - script: bash $TRAVIS_BUILD_DIR/.github/scripts/on-push.sh esp32 1 1 - - - name: "Build Platformio ESP8266" - if: tag IS blank AND (type = pull_request OR (type = push AND branch = master)) - stage: build - script: bash $TRAVIS_BUILD_DIR/.github/scripts/on-push.sh esp8266 1 1 - -notifications: - email: - on_success: change - on_failure: change - webhooks: - urls: - - https://webhooks.gitter.im/e/60e65d0c78ea0a920347 - on_success: change # options: [always|never|change] default: always - on_failure: always # options: [always|never|change] default: always - on_start: never # options: [always|never|change] default: always diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..06877f5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 2, TabWidth: 2, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: true, ColumnLimit: 0, AccessModifierOffset: -2, NamespaceIndentation: All, FixNamespaceComments: false, IndentAccessModifiers: true, PointerAlignment: Left, ReferenceAlignment: Left, ContinuationIndentWidth: 2}", + "files.exclude": { + "**/.lh": true + }, + "cSpell.words": [ + "YASOLR" + ], + "cmake.configureOnOpen": false +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 64292ec..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -set(COMPONENT_SRCDIRS - "src" -) - -set(COMPONENT_ADD_INCLUDEDIRS - "src" -) - -set(COMPONENT_REQUIRES - "arduino-esp32" - "AsyncTCP" -) - -register_component() - -target_compile_definitions(${COMPONENT_TARGET} PUBLIC -DESP32) -target_compile_options(${COMPONENT_TARGET} PRIVATE -fno-rtti) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..153d416 --- /dev/null +++ b/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. \ No newline at end of file diff --git a/README.md b/README.md index fd2c610..91cf7cc 100644 --- a/README.md +++ b/README.md @@ -1,1621 +1,19 @@ -# In this fork -- SPIFFSEditor modifications -- Added [extras](https://github.com/mathieucarbou/ESPAsyncWebServer/tree/master/extras) folder with (Win) tools for re-packing, editing, updating and compressing html to binary arrays embedded to source -- Added a [SmartSwitch](https://github.com/mathieucarbou/ESPAsyncWebServer/tree/master/examples/SmartSwitch) example to test code features -- Applied the memory optimizations from [sascha432](https://github.com/sascha432/ESPAsyncWebServer) fork -- Cookie Authentication including on Websocket part, based on [ayushsharma82](https://github.com/me-no-dev/ESPAsyncWebServer/pull/684) PR, new functions added: - - For Websocket: ```void handleHandshake(AwsHandshakeHandler handler) ``` - - For EventSource: ```void authorizeConnect(ArAuthorizeConnectHandler cb)``` -- [Additions to this README.md from jendakol' PR](https://github.com/me-no-dev/ESPAsyncWebServer/pull/770) - - [Respond with file content using a callback and extra headers](#respond-with-file-content-using-a-callback-and-extra-headers) - - [Serving static files by custom handling](#serving-static-files-by-custom-handling) - - 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 ) ------------------------------------------------------------------------------------------- +# ESP Async WebServer -# ESPAsyncWebServer -[![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) +[![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 Async WebServer.svg)](https://registry.platformio.org/libraries/mathieucarbou/ESP Async WebServer) -For help and support [![Join the chat at https://gitter.im/me-no-dev/ESPAsyncWebServer](https://badges.gitter.im/me-no-dev/ESPAsyncWebServer.svg)](https://gitter.im/me-no-dev/ESPAsyncWebServer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +Async Web Server for ESP31B -Async HTTP and WebSocket Server for ESP8266 Arduino +This fork is based on https://github.com/yubox-node-org/ESPAsyncWebServer and includes all the concurrency fixes. -For ESP8266 it requires [ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP) -To use this library you might need to have the latest git versions of [ESP8266](https://github.com/esp8266/Arduino) Arduino Core +## Changes -For ESP32 it requires [AsyncTCP](https://github.com/me-no-dev/AsyncTCP) to work -To use this library you might need to have the latest git versions of [ESP32](https://github.com/espressif/arduino-esp32) Arduino Core +- SPIFFSEditor is removed +- Arduino Json 7 compatibility +- Deployed in PlatformIO registry and Arduino IDE library manager +- CI -## Table of contents -- [ESPAsyncWebServer](#espasyncwebserver) - - [Table of contents](#table-of-contents) - - [Installation](#installation) - - [Using PlatformIO](#using-platformio) - - [Why should you care](#why-should-you-care) - - [Important things to remember](#important-things-to-remember) - - [Principles of operation](#principles-of-operation) - - [The Async Web server](#the-async-web-server) - - [Request Life Cycle](#request-life-cycle) - - [Rewrites and how do they work](#rewrites-and-how-do-they-work) - - [Handlers and how do they work](#handlers-and-how-do-they-work) - - [Responses and how do they work](#responses-and-how-do-they-work) - - [Template processing](#template-processing) - - [Libraries and projects that use AsyncWebServer](#libraries-and-projects-that-use-asyncwebserver) - - [Request Variables](#request-variables) - - [Common Variables](#common-variables) - - [Headers](#headers) - - [GET, POST and FILE parameters](#get-post-and-file-parameters) - - [FILE Upload handling](#file-upload-handling) - - [Body data handling](#body-data-handling) - - [JSON body handling with ArduinoJson](#json-body-handling-with-arduinojson) - - [Responses](#responses) - - [Redirect to another URL](#redirect-to-another-url) - - [Basic response with HTTP Code](#basic-response-with-http-code) - - [Basic response with HTTP Code and extra headers](#basic-response-with-http-code-and-extra-headers) - - [Basic response with string content](#basic-response-with-string-content) - - [Basic response with string content and extra headers](#basic-response-with-string-content-and-extra-headers) - - [Send large webpage from PROGMEM](#send-large-webpage-from-progmem) - - [Send large webpage from PROGMEM and extra headers](#send-large-webpage-from-progmem-and-extra-headers) - - [Send large webpage from PROGMEM containing templates](#send-large-webpage-from-progmem-containing-templates) - - [Send large webpage from PROGMEM containing templates and extra headers](#send-large-webpage-from-progmem-containing-templates-and-extra-headers) - - [Send binary content from PROGMEM](#send-binary-content-from-progmem) - - [Respond with content coming from a Stream](#respond-with-content-coming-from-a-stream) - - [Respond with content coming from a Stream and extra headers](#respond-with-content-coming-from-a-stream-and-extra-headers) - - [Respond with content coming from a Stream containing templates](#respond-with-content-coming-from-a-stream-containing-templates) - - [Respond with content coming from a Stream containing templates and extra headers](#respond-with-content-coming-from-a-stream-containing-templates-and-extra-headers) - - [Respond with content coming from a File](#respond-with-content-coming-from-a-file) - - [Respond with content coming from a File and extra headers](#respond-with-content-coming-from-a-file-and-extra-headers) - - [Respond with content coming from a File containing templates](#respond-with-content-coming-from-a-file-containing-templates) - - [Respond with content using a callback](#respond-with-content-using-a-callback) - - [Respond with content using a callback and extra headers](#respond-with-content-using-a-callback-and-extra-headers) - - [Respond with file content using a callback and extra headers](#respond-with-file-content-using-a-callback-and-extra-headers) - - [Respond with content using a callback containing templates](#respond-with-content-using-a-callback-containing-templates) - - [Respond with content using a callback containing templates and extra headers](#respond-with-content-using-a-callback-containing-templates-and-extra-headers) - - [Chunked Response](#chunked-response) - - [Chunked Response containing templates](#chunked-response-containing-templates) - - [Print to response](#print-to-response) - - [ArduinoJson Basic Response](#arduinojson-basic-response) - - [ArduinoJson Advanced Response](#arduinojson-advanced-response) - - [Serving static files](#serving-static-files) - - [Serving specific file by name](#serving-specific-file-by-name) - - [Serving files in directory](#serving-files-in-directory) - - [Serving static files with authentication](#serving-static-files-with-authentication) - - [Specifying Cache-Control header](#specifying-cache-control-header) - - [Specifying Date-Modified header](#specifying-date-modified-header) - - [Specifying Template Processor callback](#specifying-template-processor-callback) - - [Serving static files by custom handling](#serving-static-files-by-custom-handling) - - [Param Rewrite With Matching](#param-rewrite-with-matching) - - [Using filters](#using-filters) - - [Serve different site files in AP mode](#serve-different-site-files-in-ap-mode) - - [Rewrite to different index on AP](#rewrite-to-different-index-on-ap) - - [Serving different hosts](#serving-different-hosts) - - [Determine interface inside callbacks](#determine-interface-inside-callbacks) - - [Bad Responses](#bad-responses) - - [Respond with content using a callback without content length to HTTP/1.0 clients](#respond-with-content-using-a-callback-without-content-length-to-http10-clients) - - [Async WebSocket Plugin](#async-websocket-plugin) - - [Async WebSocket Event](#async-websocket-event) - - [Methods for sending data to a socket client](#methods-for-sending-data-to-a-socket-client) - - [Direct access to web socket message buffer](#direct-access-to-web-socket-message-buffer) - - [Limiting the number of web socket clients](#limiting-the-number-of-web-socket-clients) - - [Async Event Source Plugin](#async-event-source-plugin) - - [Setup Event Source on the server](#setup-event-source-on-the-server) - - [Setup Event Source in the browser](#setup-event-source-in-the-browser) - - [Scanning for available WiFi Networks](#scanning-for-available-wifi-networks) - - [Remove handlers and rewrites](#remove-handlers-and-rewrites) - - [Setting up the server](#setting-up-the-server) - - [Setup global and class functions as request handlers](#setup-global-and-class-functions-as-request-handlers) - - [Methods for controlling websocket connections](#methods-for-controlling-websocket-connections) - - [Adding Default Headers](#adding-default-headers) - - [Path variable](#path-variable) - -## Installation - -### Using PlatformIO - -[PlatformIO](http://platformio.org) is an open source ecosystem for IoT development with cross platform build system, library manager and full support for Espressif ESP8266/ESP32 development. It works on the popular host OS: Mac OS X, Windows, Linux 32/64, Linux ARM (like Raspberry Pi, BeagleBone, CubieBoard). - -1. Install [PlatformIO IDE](http://platformio.org/platformio-ide) -2. Create new project using "PlatformIO Home > New Project" -3. Update dev/platform to staging version: - - [Instruction for Espressif 8266](http://docs.platformio.org/en/latest/platforms/espressif8266.html#using-arduino-framework-with-staging-version) - - [Instruction for Espressif 32](http://docs.platformio.org/en/latest/platforms/espressif32.html#using-arduino-framework-with-staging-version) - 4. Add "ESP Async WebServer" to project using [Project Configuration File `platformio.ini`](http://docs.platformio.org/page/projectconf.html) and [lib_deps](http://docs.platformio.org/page/projectconf/section_env_library.html#lib-deps) option: - -```ini -[env:myboard] -platform = espressif... -board = ... -framework = arduino - -# using the latest stable version -lib_deps = ESP Async WebServer - -# or using GIT Url (the latest development version) -lib_deps = https://github.com/me-no-dev/ESPAsyncWebServer.git -``` - 5. Happy coding with PlatformIO! - -## Why should you care -- Using asynchronous network means that you can handle more than one connection at the same time -- You are called once the request is ready and parsed -- When you send the response, you are immediately ready to handle other connections - while the server is taking care of sending the response in the background -- Speed is OMG -- Easy to use API, HTTP Basic and Digest MD5 Authentication (default), ChunkedResponse -- Easily extendible to handle any type of content -- Supports Continue 100 -- Async WebSocket plugin offering different locations without extra servers or ports -- Async EventSource (Server-Sent Events) plugin to send events to the browser -- URL Rewrite plugin for conditional and permanent url rewrites -- ServeStatic plugin that supports cache, Last-Modified, default index and more -- Simple template processing engine to handle templates - -## Important things to remember -- This is fully asynchronous server and as such does not run on the loop thread. -- You can not use yield or delay or any function that uses them inside the callbacks -- The server is smart enough to know when to close the connection and free resources -- You can not send more than one response to a single request - -## Principles of operation - -### The Async Web server -- Listens for connections -- Wraps the new clients into ```Request``` -- Keeps track of clients and cleans memory -- Manages ```Rewrites``` and apply them on the request url -- Manages ```Handlers``` and attaches them to Requests - -### Request Life Cycle -- TCP connection is received by the server -- The connection is wrapped inside ```Request``` object -- When the request head is received (type, url, get params, http version and host), - the server goes through all ```Rewrites``` (in the order they were added) to rewrite the url and inject query parameters, - next, it goes through all attached ```Handlers```(in the order they were added) trying to find one - that ```canHandle``` the given request. If none are found, the default(catch-all) handler is attached. -- The rest of the request is received, calling the ```handleUpload``` or ```handleBody``` methods of the ```Handler``` if they are needed (POST+File/Body) -- When the whole request is parsed, the result is given to the ```handleRequest``` method of the ```Handler``` and is ready to be responded to -- In the ```handleRequest``` method, to the ```Request``` is attached a ```Response``` object (see below) that will serve the response data back to the client -- When the ```Response``` is sent, the client is closed and freed from the memory - -### Rewrites and how do they work -- The ```Rewrites``` are used to rewrite the request url and/or inject get parameters for a specific request url path. -- All ```Rewrites``` are evaluated on the request in the order they have been added to the server. -- The ```Rewrite``` will change the request url only if the request url (excluding get parameters) is fully match - the rewrite url, and when the optional ```Filter``` callback return true. -- Setting a ```Filter``` to the ```Rewrite``` enables to control when to apply the rewrite, decision can be based on - request url, http version, request host/port/target host, get parameters or the request client's localIP or remoteIP. -- Two filter callbacks are provided: ```ON_AP_FILTER``` to execute the rewrite when request is made to the AP interface, - ```ON_STA_FILTER``` to execute the rewrite when request is made to the STA interface. -- The ```Rewrite``` can specify a target url with optional get parameters, e.g. ```/to-url?with=params``` - -### Handlers and how do they work -- The ```Handlers``` are used for executing specific actions to particular requests -- One ```Handler``` instance can be attached to any request and lives together with the server -- Setting a ```Filter``` to the ```Handler``` enables to control when to apply the handler, decision can be based on - request url, http version, request host/port/target host, get parameters or the request client's localIP or remoteIP. -- Two filter callbacks are provided: ```ON_AP_FILTER``` to execute the rewrite when request is made to the AP interface, - ```ON_STA_FILTER``` to execute the rewrite when request is made to the STA interface. -- The ```canHandle``` method is used for handler specific control on whether the requests can be handled - and for declaring any interesting headers that the ```Request``` should parse. Decision can be based on request - method, request url, http version, request host/port/target host and get parameters -- Once a ```Handler``` is attached to given ```Request``` (```canHandle``` returned true) - that ```Handler``` takes care to receive any file/data upload and attach a ```Response``` - once the ```Request``` has been fully parsed -- ```Handlers``` are evaluated in the order they are attached to the server. The ```canHandle``` is called only - if the ```Filter``` that was set to the ```Handler``` return true. -- The first ```Handler``` that can handle the request is selected, not further ```Filter``` and ```canHandle``` are called. - -### Responses and how do they work -- The ```Response``` objects are used to send the response data back to the client -- The ```Response``` object lives with the ```Request``` and is freed on end or disconnect -- Different techniques are used depending on the response type to send the data in packets - returning back almost immediately and sending the next packet when this one is received. - Any time in between is spent to run the user loop and handle other network packets -- Responding asynchronously is probably the most difficult thing for most to understand -- Many different options exist for the user to make responding a background task - -### Template processing -- ESPAsyncWebserver contains simple template processing engine. -- Template processing can be added to most response types. -- Currently it supports only replacing template placeholders with actual values. No conditional processing, cycles, etc. -- Placeholders are delimited with ```%``` symbols. Like this: ```%TEMPLATE_PLACEHOLDER%```. -- It works by extracting placeholder name from response text and passing it to user provided function which should return actual value to be used instead of placeholder. -- Since it's user provided function, it is possible for library users to implement conditional processing and cycles themselves. -- Since it's impossible to know the actual response size after template processing step in advance (and, therefore, to include it in response headers), the response becomes [chunked](#chunked-response). - -## Libraries and projects that use AsyncWebServer -- [WebSocketToSerial](https://github.com/hallard/WebSocketToSerial) - Debug serial devices through the web browser -- [Sattrack](https://github.com/Hopperpop/Sattrack) - Track the ISS with ESP8266 -- [ESP Radio](https://github.com/Edzelf/Esp-radio) - Icecast radio based on ESP8266 and VS1053 -- [VZero](https://github.com/andig/vzero) - the Wireless zero-config controller for volkszaehler.org -- [ESPurna](https://bitbucket.org/xoseperez/espurna) - ESPurna ("spark" in Catalan) is a custom C firmware for ESP8266 based smart switches. It was originally developed with the ITead Sonoff in mind. -- [fauxmoESP](https://bitbucket.org/xoseperez/fauxmoesp) - Belkin WeMo emulator library for ESP8266. -- [ESP-RFID](https://github.com/omersiar/esp-rfid) - MFRC522 RFID Access Control Management project for ESP8266. - -## Request Variables - -### Common Variables -```cpp -request->version(); // uint8_t: 0 = HTTP/1.0, 1 = HTTP/1.1 -request->method(); // enum: HTTP_GET, HTTP_POST, HTTP_DELETE, HTTP_PUT, HTTP_PATCH, HTTP_HEAD, HTTP_OPTIONS -request->url(); // String: URL of the request (not including host, port or GET parameters) -request->host(); // String: The requested host (can be used for virtual hosting) -request->contentType(); // String: ContentType of the request (not avaiable in Handler::canHandle) -request->contentLength(); // size_t: ContentLength of the request (not avaiable in Handler::canHandle) -request->multipart(); // bool: True if the request has content type "multipart" -``` - -### Headers -```cpp -//List all collected headers -int headers = request->headers(); -int i; -for(i=0;igetHeader(i); - Serial.printf("HEADER[%s]: %s\n", h->name().c_str(), h->value().c_str()); -} - -//get specific header by name -if(request->hasHeader("MyHeader")){ - AsyncWebHeader* h = request->getHeader("MyHeader"); - Serial.printf("MyHeader: %s\n", h->value().c_str()); -} - -//List all collected headers (Compatibility) -int headers = request->headers(); -int i; -for(i=0;iheaderName(i).c_str(), request->header(i).c_str()); -} - -//get specific header by name (Compatibility) -if(request->hasHeader("MyHeader")){ - Serial.printf("MyHeader: %s\n", request->header("MyHeader").c_str()); -} -``` - -### GET, POST and FILE parameters -```cpp -//List all parameters -int params = request->params(); -for(int i=0;igetParam(i); - if(p->isFile()){ //p->isPost() is also true - Serial.printf("FILE[%s]: %s, size: %u\n", p->name().c_str(), p->value().c_str(), p->size()); - } else if(p->isPost()){ - Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str()); - } else { - Serial.printf("GET[%s]: %s\n", p->name().c_str(), p->value().c_str()); - } -} - -//Check if GET parameter exists -if(request->hasParam("download")) - AsyncWebParameter* p = request->getParam("download"); - -//Check if POST (but not File) parameter exists -if(request->hasParam("download", true)) - AsyncWebParameter* p = request->getParam("download", true); - -//Check if FILE was uploaded -if(request->hasParam("download", true, true)) - AsyncWebParameter* p = request->getParam("download", true, true); - -//List all parameters (Compatibility) -int args = request->args(); -for(int i=0;iargName(i).c_str(), request->arg(i).c_str()); -} - -//Check if parameter exists (Compatibility) -if(request->hasArg("download")) - String arg = request->arg("download"); -``` - -### FILE Upload handling -```cpp -void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){ - if(!index){ - Serial.printf("UploadStart: %s\n", filename.c_str()); - } - for(size_t i=0; i(); - // ... -}); -server.addHandler(handler); -``` - -## Responses -### Redirect to another URL -```cpp -//to local url -request->redirect("/login"); - -//to external url -request->redirect("http://esp8266.com"); -``` - -### Basic response with HTTP Code -```cpp -request->send(404); //Sends 404 File Not Found -``` - -### Basic response with HTTP Code and extra headers -```cpp -AsyncWebServerResponse *response = request->beginResponse(404); //Sends 404 File Not Found -response->addHeader("Server","ESP Async Web Server"); -request->send(response); -``` - -### Basic response with string content -```cpp -request->send(200, "text/plain", "Hello World!"); -``` - -### Basic response with string content and extra headers -```cpp -AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", "Hello World!"); -response->addHeader("Server","ESP Async Web Server"); -request->send(response); -``` - -### Send large webpage from PROGMEM -```cpp -const char index_html[] PROGMEM = "..."; // large char array, tested with 14k -request->send_P(200, "text/html", index_html); -``` - -### Send large webpage from PROGMEM and extra headers -```cpp -const char index_html[] PROGMEM = "..."; // large char array, tested with 14k -AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", index_html); -response->addHeader("Server","ESP Async Web Server"); -request->send(response); -``` - -### Send large webpage from PROGMEM containing templates -```cpp -String processor(const String& var) -{ - if(var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - return String(); -} - -// ... - -const char index_html[] PROGMEM = "..."; // large char array, tested with 14k -request->send_P(200, "text/html", index_html, processor); -``` - -### Send large webpage from PROGMEM containing templates and extra headers -```cpp -String processor(const String& var) -{ - if(var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - return String(); -} - -// ... - -const char index_html[] PROGMEM = "..."; // large char array, tested with 14k -AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", index_html, processor); -response->addHeader("Server","ESP Async Web Server"); -request->send(response); -``` - -### Send binary content from PROGMEM -```cpp - -//File: favicon.ico.gz, Size: 726 -#define favicon_ico_gz_len 726 -const uint8_t favicon_ico_gz[] PROGMEM = { -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00, 0x00 -}; - -AsyncWebServerResponse *response = request->beginResponse_P(200, "image/x-icon", favicon_ico_gz, favicon_ico_gz_len); -response->addHeader("Content-Encoding", "gzip"); -request->send(response); -``` - -### Respond with content coming from a Stream -```cpp -//read 12 bytes from Serial and send them as Content Type text/plain -request->send(Serial, "text/plain", 12); -``` - -### Respond with content coming from a Stream and extra headers -```cpp -//read 12 bytes from Serial and send them as Content Type text/plain -AsyncWebServerResponse *response = request->beginResponse(Serial, "text/plain", 12); -response->addHeader("Server","ESP Async Web Server"); -request->send(response); -``` - -### Respond with content coming from a Stream containing templates -```cpp -String processor(const String& var) -{ - if(var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - return String(); -} - -// ... - -//read 12 bytes from Serial and send them as Content Type text/plain -request->send(Serial, "text/plain", 12, processor); -``` - -### Respond with content coming from a Stream containing templates and extra headers -```cpp -String processor(const String& var) -{ - if(var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - return String(); -} - -// ... - -//read 12 bytes from Serial and send them as Content Type text/plain -AsyncWebServerResponse *response = request->beginResponse(Serial, "text/plain", 12, processor); -response->addHeader("Server","ESP Async Web Server"); -request->send(response); -``` - -### Respond with content coming from a File -```cpp -//Send index.htm with default content type -request->send(SPIFFS, "/index.htm"); - -//Send index.htm as text -request->send(SPIFFS, "/index.htm", "text/plain"); - -//Download index.htm -request->send(SPIFFS, "/index.htm", String(), true); -``` - -### Respond with content coming from a File and extra headers -```cpp -//Send index.htm with default content type -AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/index.htm"); - -//Send index.htm as text -AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/index.htm", "text/plain"); - -//Download index.htm -AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/index.htm", String(), true); - -response->addHeader("Server","ESP Async Web Server"); -request->send(response); -``` - -### Respond with content coming from a File containing templates -Internally uses [Chunked Response](#chunked-response). - -Index.htm contents: -``` -%HELLO_FROM_TEMPLATE% -``` - -Somewhere in source files: -```cpp -String processor(const String& var) -{ - if(var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - return String(); -} - -// ... - -//Send index.htm with template processor function -request->send(SPIFFS, "/index.htm", String(), false, processor); -``` - -### Respond with content using a callback -```cpp -//send 128 bytes as plain text -request->send("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //index equals the amount of bytes that have been already sent - //You will not be asked for more bytes once the content length has been reached. - //Keep in mind that you can not delay or yield waiting for more data! - //Send what you currently have and you will be asked for more again - return mySource.read(buffer, maxLen); -}); -``` - -### Respond with content using a callback and extra headers -```cpp -//send 128 bytes as plain text -AsyncWebServerResponse *response = request->beginResponse("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //index equals the amount of bytes that have been already sent - //You will not be asked for more bytes once the content length has been reached. - //Keep in mind that you can not delay or yield waiting for more data! - //Send what you currently have and you will be asked for more again - return mySource.read(buffer, maxLen); -}); -response->addHeader("Server","ESP Async Web Server"); -request->send(response); -``` - -### Respond with file content using a callback and extra headers - -With this code your ESP is able to serve even large (large in terms of ESP, e.g. 100kB) files -without memory problems. - -You need to create a file handler in outer function (to have a single one for request) but use -it in a lambda. The catch is that the lambda has it's own lifecycle which may/will cause it's -called after the original function is over thus the original file handle is destroyed. Using the -captured `&file` in the lambda then causes segfault (Hello, Exception 9!) and the whole ESP crashes. -By using this code, you tell the compiler to move the handle into the lambda so it won't be -destroyed when outer function (that one where you call `request->send(response)`) ends. - -```cpp -const File file = ... // e.g. SPIFFS.open(path, "r"); - -const contentType = "application/javascript"; - -AsyncWebServerResponse *response = request->beginResponse( - contentType, - file.size(), - [file](uint8_t *buffer, size_t maxLen, size_t total) mutable -> size_t { - int bytes = file.read(buffer, maxLen); - - // close file at the end - if (bytes + total == file.size()) file.close(); - - return max(0, bytes); // return 0 even when no bytes were loaded - } -); - -if (gzipped) { - response->addHeader(F("Content-Encoding"), F("gzip")); -} - -request->send(response); -``` - -### Respond with content using a callback containing templates -```cpp -String processor(const String& var) -{ - if(var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - return String(); -} - -// ... - -//send 128 bytes as plain text -request->send("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //index equals the amount of bytes that have been already sent - //You will not be asked for more bytes once the content length has been reached. - //Keep in mind that you can not delay or yield waiting for more data! - //Send what you currently have and you will be asked for more again - return mySource.read(buffer, maxLen); -}, processor); -``` - -### Respond with content using a callback containing templates and extra headers -```cpp -String processor(const String& var) -{ - if(var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - return String(); -} - -// ... - -//send 128 bytes as plain text -AsyncWebServerResponse *response = request->beginResponse("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //index equals the amount of bytes that have been already sent - //You will not be asked for more bytes once the content length has been reached. - //Keep in mind that you can not delay or yield waiting for more data! - //Send what you currently have and you will be asked for more again - return mySource.read(buffer, maxLen); -}, processor); -response->addHeader("Server","ESP Async Web Server"); -request->send(response); -``` - -### Chunked Response -Used when content length is unknown. Works best if the client supports HTTP/1.1 -```cpp -AsyncWebServerResponse *response = request->beginChunkedResponse("text/plain", [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //index equals the amount of bytes that have been already sent - //You will be asked for more data until 0 is returned - //Keep in mind that you can not delay or yield waiting for more data! - return mySource.read(buffer, maxLen); -}); -response->addHeader("Server","ESP Async Web Server"); -request->send(response); -``` - -### Chunked Response containing templates -Used when content length is unknown. Works best if the client supports HTTP/1.1 -```cpp -String processor(const String& var) -{ - if(var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - return String(); -} - -// ... - -AsyncWebServerResponse *response = request->beginChunkedResponse("text/plain", [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //index equals the amount of bytes that have been already sent - //You will be asked for more data until 0 is returned - //Keep in mind that you can not delay or yield waiting for more data! - return mySource.read(buffer, maxLen); -}, processor); -response->addHeader("Server","ESP Async Web Server"); -request->send(response); -``` - -### Print to response -```cpp -AsyncResponseStream *response = request->beginResponseStream("text/html"); -response->addHeader("Server","ESP Async Web Server"); -response->printf("Webpage at %s", request->url().c_str()); - -response->print("

Hello "); -response->print(request->client()->remoteIP()); -response->print("

"); - -response->print("

General

"); -response->print("
    "); -response->printf("
  • Version: HTTP/1.%u
  • ", request->version()); -response->printf("
  • Method: %s
  • ", request->methodToString()); -response->printf("
  • URL: %s
  • ", request->url().c_str()); -response->printf("
  • Host: %s
  • ", request->host().c_str()); -response->printf("
  • ContentType: %s
  • ", request->contentType().c_str()); -response->printf("
  • ContentLength: %u
  • ", request->contentLength()); -response->printf("
  • Multipart: %s
  • ", request->multipart()?"true":"false"); -response->print("
"); - -response->print("

Headers

"); -response->print("
    "); -int headers = request->headers(); -for(int i=0;igetHeader(i); - response->printf("
  • %s: %s
  • ", h->name().c_str(), h->value().c_str()); -} -response->print("
"); - -response->print("

Parameters

"); -response->print("
    "); -int params = request->params(); -for(int i=0;igetParam(i); - if(p->isFile()){ - response->printf("
  • FILE[%s]: %s, size: %u
  • ", p->name().c_str(), p->value().c_str(), p->size()); - } else if(p->isPost()){ - response->printf("
  • POST[%s]: %s
  • ", p->name().c_str(), p->value().c_str()); - } else { - response->printf("
  • GET[%s]: %s
  • ", p->name().c_str(), p->value().c_str()); - } -} -response->print("
"); - -response->print(""); -//send the response last -request->send(response); -``` - -### ArduinoJson Basic Response -This way of sending Json is great for when the result is below 4KB -```cpp -#include "AsyncJson.h" -#include "ArduinoJson.h" - - -AsyncResponseStream *response = request->beginResponseStream("application/json"); -DynamicJsonBuffer jsonBuffer; -JsonObject &root = jsonBuffer.createObject(); -root["heap"] = ESP.getFreeHeap(); -root["ssid"] = WiFi.SSID(); -root.printTo(*response); -request->send(response); -``` - -### ArduinoJson Advanced Response -This response can handle really large Json objects (tested to 40KB) -There isn't any noticeable speed decrease for small results with the method above -Since ArduinoJson does not allow reading parts of the string, the whole Json has to -be passed every time a chunks needs to be sent, which shows speed decrease proportional -to the resulting json packets -```cpp -#include "AsyncJson.h" -#include "ArduinoJson.h" - - -AsyncJsonResponse * response = new AsyncJsonResponse(); -response->addHeader("Server","ESP Async Web Server"); -JsonObject& root = response->getRoot(); -root["heap"] = ESP.getFreeHeap(); -root["ssid"] = WiFi.SSID(); -response->setLength(); -request->send(response); -``` - -## Serving static files -In addition to serving files from SPIFFS as described above, the server provide a dedicated handler that optimize the -performance of serving files from SPIFFS - ```AsyncStaticWebHandler```. Use ```server.serveStatic()``` function to -initialize and add a new instance of ```AsyncStaticWebHandler``` to the server. -The Handler will not handle the request if the file does not exists, e.g. the server will continue to look for another -handler that can handle the request. -Notice that you can chain setter functions to setup the handler, or keep a pointer to change it at a later time. - -### Serving specific file by name -```cpp -// Serve the file "/www/page.htm" when request url is "/page.htm" -server.serveStatic("/page.htm", SPIFFS, "/www/page.htm"); -``` - -### Serving files in directory -To serve files in a directory, the path to the files should specify a directory in SPIFFS and ends with "/". -```cpp -// Serve files in directory "/www/" when request url starts with "/" -// Request to the root or none existing files will try to server the defualt -// file name "index.htm" if exists -server.serveStatic("/", SPIFFS, "/www/"); - -// Server with different default file -server.serveStatic("/", SPIFFS, "/www/").setDefaultFile("default.html"); -``` - -### Serving static files with authentication - -```cpp -server - .serveStatic("/", SPIFFS, "/www/") - .setDefaultFile("default.html") - .setAuthentication("user", "pass"); -``` - -### Specifying Cache-Control header -It is possible to specify Cache-Control header value to reduce the number of calls to the server once the client loaded -the files. For more information on Cache-Control values see [Cache-Control](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9) -```cpp -// Cache responses for 10 minutes (600 seconds) -server.serveStatic("/", SPIFFS, "/www/").setCacheControl("max-age=600"); - -//*** Change Cache-Control after server setup *** - -// During setup - keep a pointer to the handler -AsyncStaticWebHandler* handler = &server.serveStatic("/", SPIFFS, "/www/").setCacheControl("max-age=600"); - -// At a later event - change Cache-Control -handler->setCacheControl("max-age=30"); -``` - -### Specifying Date-Modified header -It is possible to specify Date-Modified header to enable the server to return Not-Modified (304) response for requests -with "If-Modified-Since" header with the same value, instead of responding with the actual file content. -```cpp -// Update the date modified string every time files are updated -server.serveStatic("/", SPIFFS, "/www/").setLastModified("Mon, 20 Jun 2016 14:00:00 GMT"); - -//*** Chage last modified value at a later stage *** - -// During setup - read last modified value from config or EEPROM -String date_modified = loadDateModified(); -AsyncStaticWebHandler* handler = &server.serveStatic("/", SPIFFS, "/www/"); -handler->setLastModified(date_modified); - -// At a later event when files are updated -String date_modified = getNewDateModfied(); -saveDateModified(date_modified); // Save for next reset -handler->setLastModified(date_modified); -``` - -### Specifying Template Processor callback -It is possible to specify template processor for static files. For information on template processor see -[Respond with content coming from a File containing templates](#respond-with-content-coming-from-a-file-containing-templates). -```cpp -String processor(const String& var) -{ - if(var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - return String(); -} - -// ... - -server.serveStatic("/", SPIFFS, "/www/").setTemplateProcessor(processor); -``` - -### Serving static files by custom handling - -It may happen your static files are too big and the ESP will crash the request before it sends the whole file. -In that case, you can handle static files with custom file serving through not found handler. - -This code below is more-or-less equivalent to this: -```cpp -webServer.serveStatic("/", SPIFFS, STATIC_FILES_PREFIX).setDefaultFile("index.html") -``` - -First, declare the handling function: -```cpp -bool handleStaticFile(AsyncWebServerRequest *request) { - String path = STATIC_FILES_PREFIX + request->url(); - - if (path.endsWith("/")) path += F("index.html"); - - String contentType = getContentType(path); - String pathWithGz = path + ".gz"; - - if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) { - bool gzipped = false; - if (SPIFFS.exists(pathWithGz)) { - gzipped = true; - path += ".gz"; - } - - // TODO serve the file - - return true; - } - - return false; -} -``` -And then configure your webserver: -```cpp -webServer.onNotFound([](AsyncWebServerRequest *request) { - if (handleStaticFile(request)) return; - - request->send(404); -}); -``` - -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) -For actual serving the file. - -## Param Rewrite With Matching -It is possible to rewrite the request url with parameter matchg. Here is an example with one parameter: -Rewrite for example "/radio/{frequence}" -> "/radio?f={frequence}" - -```cpp -class OneParamRewrite : public AsyncWebRewrite -{ - protected: - String _urlPrefix; - int _paramIndex; - String _paramsBackup; - - public: - OneParamRewrite(const char* from, const char* to) - : AsyncWebRewrite(from, to) { - - _paramIndex = _from.indexOf('{'); - - if( _paramIndex >=0 && _from.endsWith("}")) { - _urlPrefix = _from.substring(0, _paramIndex); - int index = _params.indexOf('{'); - if(index >= 0) { - _params = _params.substring(0, index); - } - } else { - _urlPrefix = _from; - } - _paramsBackup = _params; - } - - bool match(AsyncWebServerRequest *request) override { - if(request->url().startsWith(_urlPrefix)) { - if(_paramIndex >= 0) { - _params = _paramsBackup + request->url().substring(_paramIndex); - } else { - _params = _paramsBackup; - } - return true; - - } else { - return false; - } - } -}; -``` - -Usage: - -```cpp - server.addRewrite( new OneParamRewrite("/radio/{frequence}", "/radio?f={frequence}") ); -``` - -## Using filters -Filters can be set to `Rewrite` or `Handler` in order to control when to apply the rewrite and consider the handler. -A filter is a callback function that evaluates the request and return a boolean `true` to include the item -or `false` to exclude it. -Two filter callback are provided for convince: -* `ON_STA_FILTER` - return true when requests are made to the STA (station mode) interface. -* `ON_AP_FILTER` - return true when requests are made to the AP (access point) interface. - -### Serve different site files in AP mode -```cpp -server.serveStatic("/", SPIFFS, "/www/").setFilter(ON_STA_FILTER); -server.serveStatic("/", SPIFFS, "/ap/").setFilter(ON_AP_FILTER); -``` - -### Rewrite to different index on AP -```cpp -// Serve the file "/www/index-ap.htm" in AP, and the file "/www/index.htm" on STA -server.rewrite("/", "index.htm"); -server.rewrite("/index.htm", "index-ap.htm").setFilter(ON_AP_FILTER); -server.serveStatic("/", SPIFFS, "/www/"); -``` - -### Serving different hosts -```cpp -// Filter callback using request host -bool filterOnHost1(AsyncWebServerRequest *request) { return request->host() == "host1"; } - -// Server setup: server files in "/host1/" to requests for "host1", and files in "/www/" otherwise. -server.serveStatic("/", SPIFFS, "/host1/").setFilter(filterOnHost1); -server.serveStatic("/", SPIFFS, "/www/"); -``` - -### Determine interface inside callbacks -```cpp - String RedirectUrl = "http://"; - if (ON_STA_FILTER(request)) { - RedirectUrl += WiFi.localIP().toString(); - } else { - RedirectUrl += WiFi.softAPIP().toString(); - } - RedirectUrl += "/index.htm"; - request->redirect(RedirectUrl); -``` - -## Bad Responses -Some responses are implemented, but you should not use them, because they do not conform to HTTP. -The following example will lead to unclean close of the connection and more time wasted -than providing the length of the content - -### Respond with content using a callback without content length to HTTP/1.0 clients -```cpp -//This is used as fallback for chunked responses to HTTP/1.0 Clients -request->send("text/plain", 0, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //You will be asked for more data until 0 is returned - //Keep in mind that you can not delay or yield waiting for more data! - return mySource.read(buffer, maxLen); -}); -``` - -## Async WebSocket Plugin -The server includes a web socket plugin which lets you define different WebSocket locations to connect to -without starting another listening service or using different port - -### Async WebSocket Event -```cpp - -void onEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){ - if(type == WS_EVT_CONNECT){ - //client connected - os_printf("ws[%s][%u] connect\n", server->url(), client->id()); - client->printf("Hello Client %u :)", client->id()); - client->ping(); - } else if(type == WS_EVT_DISCONNECT){ - //client disconnected - os_printf("ws[%s][%u] disconnect: %u\n", server->url(), client->id()); - } else if(type == WS_EVT_ERROR){ - //error was received from the other end - os_printf("ws[%s][%u] error(%u): %s\n", server->url(), client->id(), *((uint16_t*)arg), (char*)data); - } else if(type == WS_EVT_PONG){ - //pong message was received (in response to a ping request maybe) - os_printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len)?(char*)data:""); - } else if(type == WS_EVT_DATA){ - //data packet - AwsFrameInfo * info = (AwsFrameInfo*)arg; - if(info->final && info->index == 0 && info->len == len){ - //the whole message is in a single frame and we got all of it's data - os_printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT)?"text":"binary", info->len); - if(info->opcode == WS_TEXT){ - data[len] = 0; - os_printf("%s\n", (char*)data); - } else { - for(size_t i=0; i < info->len; i++){ - os_printf("%02x ", data[i]); - } - os_printf("\n"); - } - if(info->opcode == WS_TEXT) - client->text("I got your text message"); - else - client->binary("I got your binary message"); - } else { - //message is comprised of multiple frames or the frame is split into multiple packets - if(info->index == 0){ - if(info->num == 0) - os_printf("ws[%s][%u] %s-message start\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary"); - os_printf("ws[%s][%u] frame[%u] start[%llu]\n", server->url(), client->id(), info->num, info->len); - } - - os_printf("ws[%s][%u] frame[%u] %s[%llu - %llu]: ", server->url(), client->id(), info->num, (info->message_opcode == WS_TEXT)?"text":"binary", info->index, info->index + len); - if(info->message_opcode == WS_TEXT){ - data[len] = 0; - os_printf("%s\n", (char*)data); - } else { - for(size_t i=0; i < len; i++){ - os_printf("%02x ", data[i]); - } - os_printf("\n"); - } - - if((info->index + len) == info->len){ - os_printf("ws[%s][%u] frame[%u] end[%llu]\n", server->url(), client->id(), info->num, info->len); - if(info->final){ - os_printf("ws[%s][%u] %s-message end\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary"); - if(info->message_opcode == WS_TEXT) - client->text("I got your text message"); - else - client->binary("I got your binary message"); - } - } - } - } -} -``` - -### Methods for sending data to a socket client -```cpp - - - -//Server methods -AsyncWebSocket ws("/ws"); -//printf to a client -ws.printf((uint32_t)client_id, arguments...); -//printf to all clients -ws.printfAll(arguments...); -//printf_P to a client -ws.printf_P((uint32_t)client_id, PSTR(format), arguments...); -//printfAll_P to all clients -ws.printfAll_P(PSTR(format), arguments...); -//send text to a client -ws.text((uint32_t)client_id, (char*)text); -ws.text((uint32_t)client_id, (uint8_t*)text, (size_t)len); -//send text from PROGMEM to a client -ws.text((uint32_t)client_id, PSTR("text")); -const char flash_text[] PROGMEM = "Text to send" -ws.text((uint32_t)client_id, FPSTR(flash_text)); -//send text to all clients -ws.textAll((char*)text); -ws.textAll((uint8_t*)text, (size_t)len); -//send binary to a client -ws.binary((uint32_t)client_id, (char*)binary); -ws.binary((uint32_t)client_id, (uint8_t*)binary, (size_t)len); -//send binary from PROGMEM to a client -const uint8_t flash_binary[] PROGMEM = { 0x01, 0x02, 0x03, 0x04 }; -ws.binary((uint32_t)client_id, flash_binary, 4); -//send binary to all clients -ws.binaryAll((char*)binary); -ws.binaryAll((uint8_t*)binary, (size_t)len); -//HTTP Authenticate before switch to Websocket protocol -ws.setAuthentication("user", "pass"); - -//client methods -AsyncWebSocketClient * client; -//printf -client->printf(arguments...); -//printf_P -client->printf_P(PSTR(format), arguments...); -//send text -client->text((char*)text); -client->text((uint8_t*)text, (size_t)len); -//send text from PROGMEM -client->text(PSTR("text")); -const char flash_text[] PROGMEM = "Text to send"; -client->text(FPSTR(flash_text)); -//send binary -client->binary((char*)binary); -client->binary((uint8_t*)binary, (size_t)len); -//send binary from PROGMEM -const uint8_t flash_binary[] PROGMEM = { 0x01, 0x02, 0x03, 0x04 }; -client->binary(flash_binary, 4); -``` - -### Direct access to web socket message buffer -When sending a web socket message using the above methods a buffer is created. Under certain circumstances you might want to manipulate or populate this buffer directly from your application, for example to prevent unnecessary duplications of the data. This example below shows how to create a buffer and print data to it from an ArduinoJson object then send it. - -```cpp -void sendDataWs(AsyncWebSocketClient * client) -{ - DynamicJsonBuffer jsonBuffer; - JsonObject& root = jsonBuffer.createObject(); - root["a"] = "abc"; - root["b"] = "abcd"; - root["c"] = "abcde"; - root["d"] = "abcdef"; - root["e"] = "abcdefg"; - size_t len = root.measureLength(); - AsyncWebSocketMessageBuffer * buffer = ws.makeBuffer(len); // creates a buffer (len + 1) for you. - if (buffer) { - root.printTo((char *)buffer->get(), len + 1); - if (client) { - client->text(buffer); - } else { - ws.textAll(buffer); - } - } -} -``` - -### Limiting the number of web socket clients -Browsers sometimes do not correctly close the websocket connection, even when the close() function is called in javascript. This will eventually exhaust the web server's resources and will cause the server to crash. Periodically calling the cleanClients() function from the main loop() function limits the number of clients by closing the oldest client when the maximum number of clients has been exceeded. This can called be every cycle, however, if you wish to use less power, then calling as infrequently as once per second is sufficient. - -```cpp -void loop(){ - ws.cleanupClients(); -} -``` - - -## Async Event Source Plugin -The server includes EventSource (Server-Sent Events) plugin which can be used to send short text events to the browser. -Difference between EventSource and WebSockets is that EventSource is single direction, text-only protocol. - -### Setup Event Source on the server -```cpp -AsyncWebServer server(80); -AsyncEventSource events("/events"); - -void setup(){ - // setup ...... - events.onConnect([](AsyncEventSourceClient *client){ - if(client->lastId()){ - Serial.printf("Client reconnected! Last message ID that it gat is: %u\n", client->lastId()); - } - //send event with message "hello!", id current millis - // and set reconnect delay to 1 second - client->send("hello!",NULL,millis(),1000); - }); - //HTTP Basic authentication - events.setAuthentication("user", "pass"); - server.addHandler(&events); - // setup ...... -} - -void loop(){ - if(eventTriggered){ // your logic here - //send event "myevent" - events.send("my event content","myevent",millis()); - } -} -``` - -### Setup Event Source in the browser -```javascript -if (!!window.EventSource) { - var source = new EventSource('/events'); - - source.addEventListener('open', function(e) { - console.log("Events Connected"); - }, false); - - source.addEventListener('error', function(e) { - if (e.target.readyState != EventSource.OPEN) { - console.log("Events Disconnected"); - } - }, false); - - source.addEventListener('message', function(e) { - console.log("message", e.data); - }, false); - - source.addEventListener('myevent', function(e) { - console.log("myevent", e.data); - }, false); -} -``` - -## Scanning for available WiFi Networks -```cpp -//First request will return 0 results unless you start scan from somewhere else (loop/setup) -//Do not request more often than 3-5 seconds -server.on("/scan", HTTP_GET, [](AsyncWebServerRequest *request){ - String json = "["; - int n = WiFi.scanComplete(); - if(n == -2){ - WiFi.scanNetworks(true); - } else if(n){ - for (int i = 0; i < n; ++i){ - if(i) json += ","; - json += "{"; - json += "\"rssi\":"+String(WiFi.RSSI(i)); - json += ",\"ssid\":\""+WiFi.SSID(i)+"\""; - json += ",\"bssid\":\""+WiFi.BSSIDstr(i)+"\""; - json += ",\"channel\":"+String(WiFi.channel(i)); - json += ",\"secure\":"+String(WiFi.encryptionType(i)); - json += ",\"hidden\":"+String(WiFi.isHidden(i)?"true":"false"); - json += "}"; - } - WiFi.scanDelete(); - if(WiFi.scanComplete() == -2){ - WiFi.scanNetworks(true); - } - } - json += "]"; - request->send(200, "application/json", json); - json = String(); -}); -``` - -## Remove handlers and rewrites - -Server goes through handlers in same order as they were added. You can't simple add handler with same path to override them. -To remove handler: -```arduino -// save callback for particular URL path -auto handler = server.on("/some/path", [](AsyncWebServerRequest *request){ - //do something useful -}); -// when you don't need handler anymore remove it -server.removeHandler(&handler); - -// same with rewrites -server.removeRewrite(&someRewrite); - -server.onNotFound([](AsyncWebServerRequest *request){ - request->send(404); -}); - -// remove server.onNotFound handler -server.onNotFound(NULL); - -// remove all rewrites, handlers and onNotFound/onFileUpload/onRequestBody callbacks -server.reset(); -``` - -## Setting up the server -```cpp -#include "ESPAsyncTCP.h" -#include "ESPAsyncWebServer.h" - -AsyncWebServer server(80); -AsyncWebSocket ws("/ws"); // access at ws://[esp ip]/ws -AsyncEventSource events("/events"); // event source (Server-Sent events) - -const char* ssid = "your-ssid"; -const char* password = "your-pass"; -const char* http_username = "admin"; -const char* http_password = "admin"; - -//flag to use from web update to reboot the ESP -bool shouldReboot = false; - -void onRequest(AsyncWebServerRequest *request){ - //Handle Unknown Request - request->send(404); -} - -void onBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){ - //Handle body -} - -void onUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){ - //Handle upload -} - -void onEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){ - //Handle WebSocket event -} - -void setup(){ - Serial.begin(115200); - WiFi.mode(WIFI_STA); - WiFi.begin(ssid, password); - if (WiFi.waitForConnectResult() != WL_CONNECTED) { - Serial.printf("WiFi Failed!\n"); - return; - } - - // attach AsyncWebSocket - ws.onEvent(onEvent); - server.addHandler(&ws); - - // attach AsyncEventSource - server.addHandler(&events); - - // respond to GET requests on URL /heap - server.on("/heap", HTTP_GET, [](AsyncWebServerRequest *request){ - request->send(200, "text/plain", String(ESP.getFreeHeap())); - }); - - // upload a file to /upload - server.on("/upload", HTTP_POST, [](AsyncWebServerRequest *request){ - request->send(200); - }, onUpload); - - // send a file when /index is requested - server.on("/index", HTTP_ANY, [](AsyncWebServerRequest *request){ - request->send(SPIFFS, "/index.htm"); - }); - - // HTTP basic authentication - server.on("/login", HTTP_GET, [](AsyncWebServerRequest *request){ - if(!request->authenticate(http_username, http_password)) - return request->requestAuthentication(); - request->send(200, "text/plain", "Login Success!"); - }); - - // Simple Firmware Update Form - server.on("/update", HTTP_GET, [](AsyncWebServerRequest *request){ - request->send(200, "text/html", "
"); - }); - server.on("/update", HTTP_POST, [](AsyncWebServerRequest *request){ - shouldReboot = !Update.hasError(); - AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", shouldReboot?"OK":"FAIL"); - response->addHeader("Connection", "close"); - request->send(response); - },[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){ - if(!index){ - Serial.printf("Update Start: %s\n", filename.c_str()); - Update.runAsync(true); - if(!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000)){ - Update.printError(Serial); - } - } - if(!Update.hasError()){ - if(Update.write(data, len) != len){ - Update.printError(Serial); - } - } - if(final){ - if(Update.end(true)){ - Serial.printf("Update Success: %uB\n", index+len); - } else { - Update.printError(Serial); - } - } - }); - - // attach filesystem root at URL /fs - server.serveStatic("/fs", SPIFFS, "/"); - - // Catch-All Handlers - // Any request that can not find a Handler that canHandle it - // ends in the callbacks below. - server.onNotFound(onRequest); - server.onFileUpload(onUpload); - server.onRequestBody(onBody); - - server.begin(); -} - -void loop(){ - if(shouldReboot){ - Serial.println("Rebooting..."); - delay(100); - ESP.restart(); - } - static char temp[128]; - sprintf(temp, "Seconds since boot: %u", millis()/1000); - events.send(temp, "time"); //send event "time" -} -``` - -### Setup global and class functions as request handlers - -```cpp -#include -#include -#include -#include - -void handleRequest(AsyncWebServerRequest *request){} - -class WebClass { -public : - AsyncWebServer classWebServer = AsyncWebServer(81); - - WebClass(){}; - - void classRequest (AsyncWebServerRequest *request){} - - void begin(){ - // attach global request handler - classWebServer.on("/example", HTTP_ANY, handleRequest); - - // attach class request handler - classWebServer.on("/example", HTTP_ANY, std::bind(&WebClass::classRequest, this, std::placeholders::_1)); - } -}; - -AsyncWebServer globalWebServer(80); -WebClass webClassInstance; - -void setup() { - // attach global request handler - globalWebServer.on("/example", HTTP_ANY, handleRequest); - - // attach class request handler - globalWebServer.on("/example", HTTP_ANY, std::bind(&WebClass::classRequest, webClassInstance, std::placeholders::_1)); -} - -void loop() { - -} -``` - -### Methods for controlling websocket connections - -```cpp - // Disable client connections if it was activated - if ( ws.enabled() ) - ws.enable(false); - - // enable client connections if it was disabled - if ( !ws.enabled() ) - ws.enable(true); -``` - -Example of OTA code - -```cpp - // OTA callbacks - ArduinoOTA.onStart([]() { - // Clean SPIFFS - SPIFFS.end(); - - // Disable client connections - ws.enable(false); - - // Advertise connected clients what's going on - ws.textAll("OTA Update Started"); - - // Close them - ws.closeAll(); - - }); - -``` - -### Adding Default Headers - -In some cases, such as when working with CORS, or with some sort of custom authentication system, -you might need to define a header that should get added to all responses (including static, websocket and EventSource). -The DefaultHeaders singleton allows you to do this. - -Example: - -```cpp -DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*"); -webServer.begin(); -``` - -*NOTE*: You will still need to respond to the OPTIONS method for CORS pre-flight in most cases. (unless you are only using GET) - -This is one option: - -```cpp -webServer.onNotFound([](AsyncWebServerRequest *request) { - if (request->method() == HTTP_OPTIONS) { - request->send(200); - } else { - request->send(404); - } -}); -``` - -### Path variable - -With path variable you can create a custom regex rule for a specific parameter in a route. -For example we want a `sensorId` parameter in a route rule to match only a integer. - -```cpp - server.on("^\\/sensor\\/([0-9]+)$", HTTP_GET, [] (AsyncWebServerRequest *request) { - String sensorId = request->pathArg(0); - }); -``` -*NOTE*: All regex patterns starts with `^` and ends with `$` - -To enable the `Path variable` support, you have to define the buildflag `-DASYNCWEBSERVER_REGEX`. - - -For Arduino IDE create/update `platform.local.txt`: - -`Windows`: C:\Users\(username)\AppData\Local\Arduino15\packages\\`{espxxxx}`\hardware\\`espxxxx`\\`{version}`\platform.local.txt - -`Linux`: ~/.arduino15/packages/`{espxxxx}`/hardware/`{espxxxx}`/`{version}`/platform.local.txt - -Add/Update the following line: -``` - compiler.cpp.extra_flags=-DDASYNCWEBSERVER_REGEX -``` - -For platformio modify `platformio.ini`: -```ini -[env:myboard] -build_flags = - -DASYNCWEBSERVER_REGEX -``` -*NOTE*: By enabling `ASYNCWEBSERVER_REGEX`, `` will be included. This will add an 100k to your binary. +Usage and API stays the same as the original library. +Please look at the original libraries for more examples and documentation. diff --git a/_config.yml b/_config.yml deleted file mode 100644 index c419263..0000000 --- a/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-cayman \ No newline at end of file diff --git a/component.mk b/component.mk deleted file mode 100644 index bb5bb16..0000000 --- a/component.mk +++ /dev/null @@ -1,3 +0,0 @@ -COMPONENT_ADD_INCLUDEDIRS := src -COMPONENT_SRCDIRS := src -CXXFLAGS += -fno-rtti diff --git a/examples/CaptivePortal/CaptivePortal.ino b/examples/CaptivePortal/CaptivePortal.ino new file mode 100644 index 0000000..8cfe561 --- /dev/null +++ b/examples/CaptivePortal/CaptivePortal.ino @@ -0,0 +1,41 @@ +#include "ESPAsyncWebServer.h" +#include +#include +#include + +DNSServer dnsServer; +AsyncWebServer server(80); + +class CaptiveRequestHandler : public AsyncWebHandler { + public: + CaptiveRequestHandler() {} + virtual ~CaptiveRequestHandler() {} + + bool canHandle(AsyncWebServerRequest* request) { + // request->addInterestingHeader("ANY"); + return true; + } + + void handleRequest(AsyncWebServerRequest* request) { + AsyncResponseStream* response = request->beginResponseStream("text/html"); + response->print("Captive Portal"); + response->print("

This is out captive portal front page.

"); + response->printf("

You were trying to reach: http://%s%s

", request->host().c_str(), request->url().c_str()); + response->printf("

Try opening this link instead

", WiFi.softAPIP().toString().c_str()); + response->print(""); + request->send(response); + } +}; + +void setup() { + // your other setup stuff... + WiFi.softAP("esp-captive"); + dnsServer.start(53, "*", WiFi.softAPIP()); + server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); // only when requested from AP + // more handlers... + server.begin(); +} + +void loop() { + dnsServer.processNextRequest(); +} \ No newline at end of file diff --git a/examples/SimpleServer/SimpleServer.ino b/examples/SimpleServer/SimpleServer.ino new file mode 100644 index 0000000..8cfe561 --- /dev/null +++ b/examples/SimpleServer/SimpleServer.ino @@ -0,0 +1,41 @@ +#include "ESPAsyncWebServer.h" +#include +#include +#include + +DNSServer dnsServer; +AsyncWebServer server(80); + +class CaptiveRequestHandler : public AsyncWebHandler { + public: + CaptiveRequestHandler() {} + virtual ~CaptiveRequestHandler() {} + + bool canHandle(AsyncWebServerRequest* request) { + // request->addInterestingHeader("ANY"); + return true; + } + + void handleRequest(AsyncWebServerRequest* request) { + AsyncResponseStream* response = request->beginResponseStream("text/html"); + response->print("Captive Portal"); + response->print("

This is out captive portal front page.

"); + response->printf("

You were trying to reach: http://%s%s

", request->host().c_str(), request->url().c_str()); + response->printf("

Try opening this link instead

", WiFi.softAPIP().toString().c_str()); + response->print(""); + request->send(response); + } +}; + +void setup() { + // your other setup stuff... + WiFi.softAP("esp-captive"); + dnsServer.start(53, "*", WiFi.softAPIP()); + server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); // only when requested from AP + // more handlers... + server.begin(); +} + +void loop() { + dnsServer.processNextRequest(); +} \ No newline at end of file diff --git a/keywords.txt b/keywords.txt deleted file mode 100755 index c391e6c..0000000 --- a/keywords.txt +++ /dev/null @@ -1,3 +0,0 @@ -JsonArray KEYWORD1 -add KEYWORD2 -createArray KEYWORD3 diff --git a/library.json b/library.json index a5a851e..45b2d8e 100644 --- a/library.json +++ b/library.json @@ -1,38 +1,40 @@ { "name": "ESP Async WebServer", - "description": "Asynchronous HTTP and WebSocket Server Library for ESP8266 and ESP32", + "description": "Asynchronous HTTP and WebSocket Server Library for ESP32", "keywords": "http,async,websocket,webserver", - "authors": { - "name": "Hristo Gochkov", - "maintainer": true - }, + "homepage": "https://github.com/mathieucarbou/ESPAsyncWebServer", "repository": { "type": "git", "url": "https://github.com/mathieucarbou/ESPAsyncWebServer.git" }, - "version": "2.1.2", + "authors": [ + { + "name": "Me-No-Dev" + }, + { + "name": "Mathieu Carbou", + "maintainer": true + } + ], "license": "LGPL-3.0", "frameworks": "arduino", "platforms": [ - "espressif8266", "espressif32" ], "dependencies": [ - { - "owner": "esphome", - "name": "ESPAsyncTCP-esphome", - "version": ">=2.0.0", - "platforms": "espressif8266" - }, { "owner": "esphome", "name": "AsyncTCP-esphome", - "version": ">=2.0.1", + "version": "^2.1.1", "platforms": "espressif32" }, { - "name": "Hash", - "platforms": "espressif8266" + "owner": "bblanchon", + "name": "ArduinoJson", + "version": "^7.0.2", + "platforms": [ + "espressif32" + ] } ] } \ No newline at end of file diff --git a/library.properties b/library.properties index 419f336..790ba2c 100644 --- a/library.properties +++ b/library.properties @@ -2,8 +2,10 @@ name=ESP Async WebServer version=2.1.2 author=Me-No-Dev maintainer=Mathieu Carbou -sentence=Async Web Server for ESP8266 and ESP31B -paragraph=Async Web Server for ESP8266 and ESP31B +sentence=Asynchronous HTTP and WebSocket Server Library for ESP32 +paragraph= category=Other url=https://github.com/mathieucarbou/ESPAsyncWebServer -architectures=* +architectures==esp32 +license=LGPL-3.0 +depends=ArduinoJson diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..cad8b22 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,23 @@ +[env] +lib_deps = + bblanchon/ArduinoJson @ 7.0.2 + esphome/AsyncTCP-esphome @ 2.1.1 + +build_flags = -Wall -Wextra + +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] +lib_dir = . +src_dir = examples/CaptivePortal +; src_dir = examples/SimpleServer + +[env:esp32] +platform = espressif32@6.5.0 +board = esp32dev +framework = arduino diff --git a/src/AsyncJson.h b/src/AsyncJson.h index a6673a8..f4e99d1 100644 --- a/src/AsyncJson.h +++ b/src/AsyncJson.h @@ -30,7 +30,7 @@ // ... }); server.addHandler(handler); - + */ #ifndef ASYNC_JSON_H_ #define ASYNC_JSON_H_ @@ -39,9 +39,9 @@ #include #if ARDUINOJSON_VERSION_MAJOR == 6 - #ifndef DYNAMIC_JSON_DOCUMENT_SIZE - #define DYNAMIC_JSON_DOCUMENT_SIZE 1024 - #endif +#ifndef DYNAMIC_JSON_DOCUMENT_SIZE +#define DYNAMIC_JSON_DOCUMENT_SIZE 1024 +#endif #endif constexpr const char* JSON_MIMETYPE = "application/json"; @@ -56,11 +56,12 @@ class ChunkPrint : public Print { size_t _to_skip; size_t _to_write; size_t _pos; + public: ChunkPrint(uint8_t* destination, size_t from, size_t len) - : _destination(destination), _to_skip(from), _to_write(len), _pos{0} {} - virtual ~ChunkPrint(){} - size_t write(uint8_t c){ + : _destination(destination), _to_skip(from), _to_write(len), _pos{0} {} + virtual ~ChunkPrint() {} + size_t write(uint8_t c) { if (_to_skip > 0) { _to_skip--; return 1; @@ -71,15 +72,13 @@ class ChunkPrint : public Print { } return 0; } - size_t write(const uint8_t *buffer, size_t size) - { + size_t write(const uint8_t* buffer, size_t size) { return this->Print::write(buffer, size); } }; -class AsyncJsonResponse: public AsyncAbstractResponse { +class AsyncJsonResponse : public AsyncAbstractResponse { protected: - #if ARDUINOJSON_VERSION_MAJOR == 5 DynamicJsonBuffer _jsonBuffer; #elif ARDUINOJSON_VERSION_MAJOR == 6 @@ -91,31 +90,30 @@ class AsyncJsonResponse: public AsyncAbstractResponse { JsonVariant _root; bool _isValid; - public: - + public: #if ARDUINOJSON_VERSION_MAJOR == 5 - AsyncJsonResponse(bool isArray=false): _isValid{false} { + AsyncJsonResponse(bool isArray = false) : _isValid{false} { _code = 200; _contentType = JSON_MIMETYPE; - if(isArray) + if (isArray) _root = _jsonBuffer.createArray(); else _root = _jsonBuffer.createObject(); } #elif ARDUINOJSON_VERSION_MAJOR == 6 - AsyncJsonResponse(bool isArray=false, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) : _jsonBuffer(maxJsonBufferSize), _isValid{false} { + AsyncJsonResponse(bool isArray = false, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) : _jsonBuffer(maxJsonBufferSize), _isValid{false} { _code = 200; _contentType = JSON_MIMETYPE; - if(isArray) + if (isArray) _root = _jsonBuffer.createNestedArray(); else _root = _jsonBuffer.createNestedObject(); } #else - AsyncJsonResponse(bool isArray=false) : _isValid{false} { + AsyncJsonResponse(bool isArray = false) : _isValid{false} { _code = 200; _contentType = JSON_MIMETYPE; - if(isArray) + if (isArray) _root = _jsonBuffer.add(); else _root = _jsonBuffer.add(); @@ -123,7 +121,7 @@ class AsyncJsonResponse: public AsyncAbstractResponse { #endif ~AsyncJsonResponse() {} - JsonVariant & getRoot() { return _root; } + JsonVariant& getRoot() { return _root; } bool _sourceValid() const { return _isValid; } size_t setLength() { @@ -133,17 +131,19 @@ class AsyncJsonResponse: public AsyncAbstractResponse { _contentLength = measureJson(_root); #endif - if (_contentLength) { _isValid = true; } + if (_contentLength) { + _isValid = true; + } return _contentLength; } - size_t getSize() { return _jsonBuffer.size(); } + size_t getSize() { return _jsonBuffer.size(); } - size_t _fillBuffer(uint8_t *data, size_t len){ + size_t _fillBuffer(uint8_t* data, size_t len) { ChunkPrint dest(data, _sentLength, len); #if ARDUINOJSON_VERSION_MAJOR == 5 - _root.printTo( dest ) ; + _root.printTo(dest); #else serializeJson(_root, dest); #endif @@ -151,118 +151,121 @@ class AsyncJsonResponse: public AsyncAbstractResponse { } }; -class PrettyAsyncJsonResponse: public AsyncJsonResponse { -public: +class PrettyAsyncJsonResponse : public AsyncJsonResponse { + public: #if ARDUINOJSON_VERSION_MAJOR == 6 - PrettyAsyncJsonResponse (bool isArray=false, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) : AsyncJsonResponse{isArray, maxJsonBufferSize} {} + PrettyAsyncJsonResponse(bool isArray = false, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) : AsyncJsonResponse{isArray, maxJsonBufferSize} {} #else - PrettyAsyncJsonResponse (bool isArray=false) : AsyncJsonResponse{isArray} {} + PrettyAsyncJsonResponse(bool isArray = false) : AsyncJsonResponse{isArray} {} #endif - size_t setLength () { + size_t setLength() { #if ARDUINOJSON_VERSION_MAJOR == 5 - _contentLength = _root.measurePrettyLength (); + _contentLength = _root.measurePrettyLength(); #else - _contentLength = measureJsonPretty(_root); + _contentLength = measureJsonPretty(_root); #endif - if (_contentLength) {_isValid = true;} - return _contentLength; - } - size_t _fillBuffer (uint8_t *data, size_t len) { - ChunkPrint dest (data, _sentLength, len); + if (_contentLength) { + _isValid = true; + } + return _contentLength; + } + size_t _fillBuffer(uint8_t* data, size_t len) { + ChunkPrint dest(data, _sentLength, len); #if ARDUINOJSON_VERSION_MAJOR == 5 - _root.prettyPrintTo (dest); + _root.prettyPrintTo(dest); #else - serializeJsonPretty(_root, dest); + serializeJsonPretty(_root, dest); #endif - return len; - } + return len; + } }; -typedef std::function ArJsonRequestHandlerFunction; +typedef std::function ArJsonRequestHandlerFunction; -class AsyncCallbackJsonWebHandler: public AsyncWebHandler { -private: -protected: - const String _uri; - WebRequestMethodComposite _method; - ArJsonRequestHandlerFunction _onRequest; - size_t _contentLength; +class AsyncCallbackJsonWebHandler : public AsyncWebHandler { + private: + protected: + const String _uri; + WebRequestMethodComposite _method; + ArJsonRequestHandlerFunction _onRequest; + size_t _contentLength; #if ARDUINOJSON_VERSION_MAJOR == 6 - const size_t maxJsonBufferSize; + const size_t maxJsonBufferSize; #endif - size_t _maxContentLength; -public: + size_t _maxContentLength; + + 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) {} + 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) {} #else - AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest) - : _uri(uri), _method(HTTP_POST|HTTP_PUT|HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384) {} + AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest) + : _uri(uri), _method(HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384) {} #endif - - void setMethod(WebRequestMethodComposite method){ _method = method; } - void setMaxContentLength(int maxContentLength){ _maxContentLength = maxContentLength; } - void onRequest(ArJsonRequestHandlerFunction fn){ _onRequest = fn; } - virtual bool canHandle(AsyncWebServerRequest *request) override final{ - if(!_onRequest) - return false; + void setMethod(WebRequestMethodComposite method) { _method = method; } + void setMaxContentLength(int maxContentLength) { _maxContentLength = maxContentLength; } + void onRequest(ArJsonRequestHandlerFunction fn) { _onRequest = fn; } - if(!(_method & request->method())) - return false; + virtual bool canHandle(AsyncWebServerRequest* request) override final { + if (!_onRequest) + return false; - if(_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri+"/"))) - return false; + if (!(_method & request->method())) + return false; - if ( !request->contentType().equalsIgnoreCase(JSON_MIMETYPE) ) - return false; + if (_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri + "/"))) + return false; - request->addInterestingHeader("ANY"); - return true; - } + if (!request->contentType().equalsIgnoreCase(JSON_MIMETYPE)) + return false; - virtual void handleRequest(AsyncWebServerRequest *request) override final { - if(_onRequest) { - if (request->_tempObject != NULL) { + request->addInterestingHeader("ANY"); + return true; + } + + virtual void handleRequest(AsyncWebServerRequest* request) override final { + if (_onRequest) { + if (request->_tempObject != NULL) { #if ARDUINOJSON_VERSION_MAJOR == 5 - DynamicJsonBuffer jsonBuffer; - JsonVariant json = jsonBuffer.parse((uint8_t*)(request->_tempObject)); - if (json.success()) { + DynamicJsonBuffer jsonBuffer; + JsonVariant json = jsonBuffer.parse((uint8_t*)(request->_tempObject)); + if (json.success()) { #elif ARDUINOJSON_VERSION_MAJOR == 6 - DynamicJsonDocument jsonBuffer(this->maxJsonBufferSize); - DeserializationError error = deserializeJson(jsonBuffer, (uint8_t*)(request->_tempObject)); - if(!error) { - JsonVariant json = jsonBuffer.as(); + DynamicJsonDocument jsonBuffer(this->maxJsonBufferSize); + DeserializationError error = deserializeJson(jsonBuffer, (uint8_t*)(request->_tempObject)); + if (!error) { + JsonVariant json = jsonBuffer.as(); #else - JsonDocument jsonBuffer; - DeserializationError error = deserializeJson(jsonBuffer, (uint8_t*)(request->_tempObject)); - if(!error) { - JsonVariant json = jsonBuffer.as(); + JsonDocument jsonBuffer; + DeserializationError error = deserializeJson(jsonBuffer, (uint8_t*)(request->_tempObject)); + if (!error) { + JsonVariant json = jsonBuffer.as(); #endif - _onRequest(request, json); - return; + _onRequest(request, json); + return; + } + } + request->send(_contentLength > _maxContentLength ? 413 : 400); + } else { + request->send(500); + } + } + virtual void handleUpload(AsyncWebServerRequest* request, const String& filename, size_t index, uint8_t* data, size_t len, bool final) override final { + } + virtual void handleBody(AsyncWebServerRequest* request, uint8_t* data, size_t len, size_t index, size_t total) override final { + if (_onRequest) { + _contentLength = total; + if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) { + request->_tempObject = malloc(total); + } + if (request->_tempObject != NULL) { + memcpy((uint8_t*)(request->_tempObject) + index, data, len); } } - request->send(_contentLength > _maxContentLength ? 413 : 400); - } else { - request->send(500); } - } - virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) override final { - } - virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) override final { - if (_onRequest) { - _contentLength = total; - if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) { - request->_tempObject = malloc(total); - } - if (request->_tempObject != NULL) { - memcpy((uint8_t*)(request->_tempObject) + index, data, len); - } - } - } - virtual bool isRequestHandlerTrivial() override final {return _onRequest ? false : true;} + virtual bool isRequestHandlerTrivial() override final { return _onRequest ? false : true; } }; #endif diff --git a/src/SPIFFSEditor.cpp b/src/SPIFFSEditor.cpp deleted file mode 100644 index 343ed79..0000000 --- a/src/SPIFFSEditor.cpp +++ /dev/null @@ -1,342 +0,0 @@ -#include "SPIFFSEditor.h" -#include - -#define EDFS - -#ifndef EDFS - #include "edit.htm.gz.h" -#endif - -#ifdef ESP32 - #define fullName(x) name(x) -#endif - -#define SPIFFS_MAXLENGTH_FILEPATH 32 -static const char excludeListFile[] PROGMEM = "/.exclude.files"; - -typedef struct ExcludeListS { - char *item; - ExcludeListS *next; -} ExcludeList; - -static ExcludeList *excludes = NULL; - -static bool matchWild(const char *pattern, const char *testee) { - const char *nxPat = NULL, *nxTst = NULL; - - while (*testee) { - if (( *pattern == '?' ) || (*pattern == *testee)){ - pattern++;testee++; - continue; - } - if (*pattern=='*'){ - nxPat=pattern++; nxTst=testee; - continue; - } - if (nxPat){ - pattern = nxPat+1; testee=++nxTst; - continue; - } - return false; - } - while (*pattern=='*'){pattern++;} - return (*pattern == 0); -} - -static bool addExclude(const char *item){ - size_t len = strlen(item); - if(!len){ - return false; - } - ExcludeList *e = (ExcludeList *)malloc(sizeof(ExcludeList)); - if(!e){ - return false; - } - e->item = (char *)malloc(len+1); - if(!e->item){ - free(e); - return false; - } - memcpy(e->item, item, len+1); - e->next = excludes; - excludes = e; - return true; -} - -static void loadExcludeList(fs::FS &_fs, const char *filename){ - static char linebuf[SPIFFS_MAXLENGTH_FILEPATH]; - fs::File excludeFile=_fs.open(filename, "r"); - if(!excludeFile){ - //addExclude("/*.js.gz"); - return; - } -#ifdef ESP32 - if(excludeFile.isDirectory()){ - excludeFile.close(); - return; - } -#endif - if (excludeFile.size() > 0){ - uint8_t idx; - bool isOverflowed = false; - while (excludeFile.available()){ - linebuf[0] = '\0'; - idx = 0; - int lastChar; - do { - lastChar = excludeFile.read(); - if(lastChar != '\r'){ - linebuf[idx++] = (char) lastChar; - } - } while ((lastChar >= 0) && (lastChar != '\n') && (idx < SPIFFS_MAXLENGTH_FILEPATH)); - - if(isOverflowed){ - isOverflowed = (lastChar != '\n'); - continue; - } - isOverflowed = (idx >= SPIFFS_MAXLENGTH_FILEPATH); - linebuf[idx-1] = '\0'; - if(!addExclude(linebuf)){ - excludeFile.close(); - return; - } - } - } - excludeFile.close(); -} - -static bool isExcluded(fs::FS &_fs, const char *filename) { - if(excludes == NULL){ - loadExcludeList(_fs, String(FPSTR(excludeListFile)).c_str()); - } - ExcludeList *e = excludes; - while(e){ - if (matchWild(e->item, filename)){ - return true; - } - e = e->next; - } - return false; -} - -// WEB HANDLER IMPLEMENTATION - -#ifdef ESP32 -SPIFFSEditor::SPIFFSEditor(const fs::FS& fs, const String& username, const String& password) -#else -SPIFFSEditor::SPIFFSEditor(const String& username, const String& password, const fs::FS& fs) -#endif -:_fs(fs) -,_username(username) -,_password(password) -,_authenticated(false) -,_startTime(0) -{} - -bool SPIFFSEditor::canHandle(AsyncWebServerRequest *request){ - if(request->url().equalsIgnoreCase(F("/edit"))){ - if(request->method() == HTTP_GET){ - if(request->hasParam(F("list"))) - return true; - if(request->hasParam(F("edit"))){ - request->_tempFile = _fs.open(request->arg(F("edit")), "r"); - if(!request->_tempFile){ - return false; - } -#ifdef ESP32 - if(request->_tempFile.isDirectory()){ - request->_tempFile.close(); - return false; - } -#endif - } - if(request->hasParam("download")){ - request->_tempFile = _fs.open(request->arg(F("download")), "r"); - if(!request->_tempFile){ - return false; - } -#ifdef ESP32 - if(request->_tempFile.isDirectory()){ - request->_tempFile.close(); - return false; - } -#endif - } - request->addInterestingHeader(F("If-Modified-Since")); - return true; - } - else if(request->method() == HTTP_POST) - return true; - else if(request->method() == HTTP_DELETE) - return true; - else if(request->method() == HTTP_PUT) - return true; - - } - return false; -} - - -void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){ - if(_username.length() && _password.length() && !request->authenticate(_username.c_str(), _password.c_str())) - return request->requestAuthentication(); - - if(request->method() == HTTP_GET){ - if(request->hasParam(F("list"))){ - String path = request->getParam(F("list"))->value(); -#ifdef ESP32 - File dir = _fs.open(path); -#else - fs::Dir dir = _fs.openDir(path); -#endif - path = String(); - String output = "["; -#ifdef ESP32 - File entry = dir.openNextFile(); - while(entry){ -#else - while(dir.next()){ - fs::File entry = dir.openFile("r"); -#endif - String fname = entry.fullName(); - if (fname.charAt(0) != '/') fname = "/" + fname; - - if (isExcluded(_fs, fname.c_str())) { -#ifdef ESP32 - entry = dir.openNextFile(); -#endif - continue; - } - if (output != "[") output += ','; - output += F("{\"type\":\""); - output += F("file"); - output += F("\",\"name\":\""); - output += String(fname); - output += F("\",\"size\":"); - output += String(entry.size()); - output += "}"; -#ifdef ESP32 - entry = dir.openNextFile(); -#else - entry.close(); -#endif - } -#ifdef ESP32 - dir.close(); -#endif - output += "]"; - request->send(200, F("application/json"), output); - output = String(); - } - else if(request->hasParam(F("edit")) || request->hasParam(F("download"))){ - request->send(request->_tempFile, request->_tempFile.fullName(), String(), request->hasParam(F("download"))); - } - else { - const char * buildTime = __DATE__ " " __TIME__ " GMT"; - if (request->header(F("If-Modified-Since")).equals(buildTime)) { - request->send(304); - } else { -#ifdef EDFS - AsyncWebServerResponse *response = request->beginResponse(_fs, F("/edit_gz"), F("text/html"), false); -#else - AsyncWebServerResponse *response = request->beginResponse_P(200, F("text/html"), edit_htm_gz, edit_htm_gz_len); -#endif - response->addHeader(F("Content-Encoding"), F("gzip")); - response->addHeader(F("Last-Modified"), buildTime); - request->send(response); - } - } - } else if(request->method() == HTTP_DELETE){ - if(request->hasParam(F("path"), true)){ - if(!(_fs.remove(request->getParam(F("path"), true)->value()))){ -#ifdef ESP32 - _fs.rmdir(request->getParam(F("path"), true)->value()); // try rmdir for littlefs -#endif - } - - request->send(200, "", String(F("DELETE: "))+request->getParam(F("path"), true)->value()); - } else - request->send(404); - } else if(request->method() == HTTP_POST){ - if(request->hasParam(F("data"), true, true) && _fs.exists(request->getParam(F("data"), true, true)->value())) - request->send(200, "", String(F("UPLOADED: "))+request->getParam(F("data"), true, true)->value()); - - else if(request->hasParam(F("rawname"), true) && request->hasParam(F("raw0"), true)){ - String rawnam = request->getParam(F("rawname"), true)->value(); - - if (_fs.exists(rawnam)) _fs.remove(rawnam); // delete it to allow a mode - - int k = 0; - uint16_t i = 0; - fs::File f = _fs.open(rawnam, "a"); - - while (request->hasParam(String(F("raw")) + String(k), true)) { //raw0 .. raw1 - if(f){ - i += f.print(request->getParam(String(F("raw")) + String(k), true)->value()); - } - k++; - } - f.close(); - request->send(200, "", String(F("IPADWRITE: ")) + rawnam + ":" + String(i)); - - } else { - request->send(500); - } - - } else if(request->method() == HTTP_PUT){ - if(request->hasParam(F("path"), true)){ - String filename = request->getParam(F("path"), true)->value(); - if(_fs.exists(filename)){ - request->send(200); - } else { -/*******************************************************/ -#ifdef ESP32 - if (strchr(filename.c_str(), '/')) { - // For file creation, silently make subdirs as needed. If any fail, - // it will be caught by the real file open later on - char *pathStr = strdup(filename.c_str()); - if (pathStr) { - // Make dirs up to the final fnamepart - char *ptr = strchr(pathStr, '/'); - while (ptr) { - *ptr = 0; - _fs.mkdir(pathStr); - *ptr = '/'; - ptr = strchr(ptr+1, '/'); - } - } - free(pathStr); - } -#endif -/*******************************************************/ - fs::File f = _fs.open(filename, "w"); - if(f){ - f.write((uint8_t)0x00); - f.close(); - request->send(200, "", String(F("CREATE: "))+filename); - } else { - request->send(500); - } - } - } else - request->send(400); - } -} - -void SPIFFSEditor::handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final){ - if(!index){ - if(!_username.length() || request->authenticate(_username.c_str(),_password.c_str())){ - _authenticated = true; - request->_tempFile = _fs.open(filename, "w"); - _startTime = millis(); - } - } - if(_authenticated && request->_tempFile){ - if(len){ - request->_tempFile.write(data,len); - } - if(final){ - request->_tempFile.close(); - } - } -} diff --git a/src/SPIFFSEditor.h b/src/SPIFFSEditor.h deleted file mode 100644 index d3b959f..0000000 --- a/src/SPIFFSEditor.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SPIFFSEditor_H_ -#define SPIFFSEditor_H_ -#include - -class SPIFFSEditor: public AsyncWebHandler { - private: - fs::FS _fs; - String _username; - String _password; - bool _authenticated; - uint32_t _startTime; - public: -#ifdef ESP32 - SPIFFSEditor(const fs::FS& fs, const String& username=String(), const String& password=String()); -#else - //SPIFFSEditor(const String& username=String(), const String& password=String(), const fs::FS& fs=SPIFFS); - SPIFFSEditor(const String& username, const String& password, const fs::FS& fs); // do not show warning that SPIFFS has been deprecated -#endif - virtual bool canHandle(AsyncWebServerRequest *request) override final; - virtual void handleRequest(AsyncWebServerRequest *request) override final; - virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) override final; - virtual bool isRequestHandlerTrivial() override final {return false;} -}; - -#endif diff --git a/src/edit.htm b/src/edit.htm deleted file mode 100644 index 5d497ea..0000000 --- a/src/edit.htm +++ /dev/null @@ -1,581 +0,0 @@ - - - - - ESP Editor - - - - - - - - - - -
-
-
-
- - - - \ No newline at end of file diff --git a/src/edit.htm.gz.h b/src/edit.htm.gz.h deleted file mode 100644 index aa77e28..0000000 --- a/src/edit.htm.gz.h +++ /dev/null @@ -1,231 +0,0 @@ - -//File: edit.htm.gz, Size: 4503 -#define edit_htm_gz_len 4503 -const uint8_t edit_htm_gz[] PROGMEM = { -0x1F,0x8B,0x08,0x08,0x5A,0xE6,0xAE,0x5F,0x02,0x00,0x65,0x64,0x69,0x74,0x2E,0x68,0x74,0x6D,0x00,0xB5, -0x1A,0x0B,0x5B,0xDB,0x36,0xF0,0xAF,0x18,0x6F,0x63,0xF6,0xE2,0x38,0x0E,0x50,0xD6,0x3A,0x18,0x16,0x1E, -0xEB,0xBB,0x50,0x12,0xDA,0xD1,0x8E,0xED,0x53,0x6C,0x25,0x56,0xB1,0x25,0xCF,0x96,0x09,0x34,0xCD,0x7F, -0xDF,0x49,0xF2,0x93,0x84,0xEE,0xF1,0x6D,0xA5,0x60,0x49,0xA7,0x3B,0xDD,0x9D,0xEE,0x25,0xD9,0x7B,0x1B, -0xC7,0xA7,0x47,0xE3,0xCB,0xB3,0x13,0x2D,0xE4,0x71,0xB4,0xBF,0x27,0xFE,0x6A,0x11,0xA2,0x33,0x4F,0xC7, -0x54,0xDF,0xDF,0x8B,0x31,0x47,0x00,0xE2,0x49,0x17,0xFF,0x91,0x93,0x1B,0x4F,0x3F,0x62,0x94,0x63,0xCA, -0xBB,0xFC,0x2E,0xC1,0xBA,0xE6,0xAB,0x9E,0xA7,0x73,0x7C,0xCB,0x7B,0x02,0x79,0xA0,0xF9,0x21,0x4A,0x33, -0xCC,0xBD,0x9C,0x4F,0xBB,0x8F,0x81,0x04,0x27,0x3C,0xC2,0xFB,0x27,0xA3,0x33,0xED,0x24,0x20,0x9C,0xA5, -0x7B,0x3D,0x35,0xB2,0x17,0x11,0x7A,0xAD,0xA5,0x38,0xF2,0x74,0x94,0x24,0x11,0xEE,0x72,0x96,0xFB,0x61, -0x97,0x00,0x4D,0x5D,0x0B,0x53,0x3C,0xF5,0xF4,0x1E,0xF2,0xB1,0x0D,0x03,0xBA,0x26,0x96,0xF3,0x74,0x12, -0xA3,0x19,0xEE,0xDD,0xAA,0x39,0x4D,0x02,0x59,0xC8,0x52,0xEE,0xE7,0x5C,0xFB,0x57,0xD8,0xFF,0x00,0x29, -0xE3,0x77,0x11,0x56,0x20,0x25,0xB3,0x9F,0x65,0xBA,0x16,0xE3,0x80,0x20,0xE0,0xC2,0x4F,0xB1,0xD0,0x5A, -0x84,0x26,0x38,0x5A,0x4C,0x19,0xA8,0x29,0x23,0x9F,0xB1,0xDB,0xDF,0x4A,0x6E,0x07,0xB2,0x3B,0x45,0x31, -0x89,0xEE,0xDC,0x0C,0xD1,0xAC,0x9B,0xE1,0x94,0x4C,0x97,0xB6,0x1F,0x2F,0x3E,0x77,0x09,0x0D,0xF0,0xAD, -0xBB,0xED,0x38,0x83,0x84,0x65,0x84,0x13,0x46,0x5D,0x34,0xC9,0x58,0x94,0x73,0x3C,0x88,0xF0,0x94,0xBB, -0x8F,0x80,0xC2,0x84,0xA5,0x01,0x4E,0xDD,0x7E,0x72,0xAB,0x01,0x88,0x04,0xDA,0x37,0x3B,0x3B,0x3B,0x83, -0x09,0xF2,0xAF,0x67,0x29,0xCB,0x69,0xD0,0xF5,0x59,0xC4,0x52,0xF7,0x9B,0xE9,0x23,0xF1,0x33,0x08,0x48, -0x96,0x44,0xE8,0xCE,0xA5,0x8C,0x62,0xC0,0xBD,0xED,0x66,0x21,0x0A,0xD8,0xDC,0x75,0x34,0x47,0xEB,0x3B, -0x40,0x24,0x9D,0x4D,0x90,0xE1,0x58,0xE2,0xC7,0xDE,0x31,0x07,0x7F,0x8B,0x5F,0x35,0x3C,0xC7,0x64,0x16, -0x72,0xF7,0x47,0xC7,0x11,0xFC,0x6B,0x79,0xB4,0x88,0x48,0xC6,0xBB,0x52,0x39,0x6A,0x3D,0xCE,0x12,0xD7, -0x91,0xAC,0xC3,0x23,0x46,0xE9,0x8C,0x50,0x68,0x24,0x28,0x08,0x08,0x9D,0xB9,0x0A,0x2D,0x22,0x8B,0x4A, -0x5A,0xD8,0x07,0xC4,0xC9,0x0D,0x1E,0xC4,0x84,0x76,0xE7,0x24,0xE0,0xA1,0xBB,0xEB,0x00,0x17,0x7E,0x9E, -0x66,0x20,0x53,0xC2,0x08,0xE5,0x38,0x95,0x68,0x59,0x82,0xE8,0x42,0x89,0x2A,0x14,0x50,0xC9,0x49,0x28, -0xEC,0x28,0xEE,0x4E,0x22,0xE6,0x5F,0x57,0x2B,0xED,0x26,0xB7,0xC5,0x5A,0x6E,0xC8,0x6E,0x70,0xBA,0xA8, -0xD5,0x25,0xB1,0x5B,0xC0,0x16,0x69,0x8C,0xF1,0xD2,0xE6,0x37,0x39,0x40,0x2D,0xF9,0x04,0x29,0x0B,0xAA, -0x4D,0x91,0xDA,0x82,0x17,0x28,0x84,0x26,0x39,0x5F,0xAC,0x6E,0x25,0x4B,0x90,0x4F,0xF8,0x9D,0xEB,0xC8, -0x69,0xD2,0x42,0xDC,0x1D,0xC7,0xD1,0x84,0xC2,0xB5,0x77,0x38,0x0D,0x10,0x45,0xD6,0x30,0x25,0x28,0xB2, -0x46,0xB5,0xCA,0xBB,0x31,0xFB,0xDC,0xCD,0xA1,0x0D,0xFD,0x08,0xFB,0x5C,0x69,0x18,0x36,0x61,0x72,0x4D, -0xF8,0x2A,0x60,0x65,0xA0,0xA1,0x2B,0xA9,0xA1,0x50,0xED,0x5E,0x1F,0x74,0x23,0xF9,0x50,0x62,0x2B,0x89, -0xBA,0x13,0xC6,0x39,0x8B,0xA5,0xBD,0x55,0xD2,0x6A,0xD2,0x64,0x1E,0xAF,0x6C,0xC7,0x7A,0xD5,0x37,0xC8, -0x0F,0x40,0xA9,0x9C,0xF8,0x28,0xEA,0xA2,0x88,0xCC,0xA8,0x1B,0x93,0x20,0x88,0x70,0xC3,0x64,0xDD,0x3C, -0x8D,0x8C,0x00,0x71,0xE4,0x2A,0x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,0x88,0x37,0x63,0x55,0xE5,0x1C,0x60, -0x5B,0xB5,0x15,0x16,0x4E,0x2A,0x22,0x6B,0x37,0xC0,0x3E,0x4B,0x91,0x9C,0x03,0x08,0x38,0x15,0x26,0xB6, -0xFC,0x49,0x86,0x5A,0x4D,0x45,0x5A,0x0D,0xD1,0x40,0x33,0x4A,0x47,0x88,0x09,0x05,0x9C,0x1B,0xE2,0xE3, -0x6E,0x42,0x6E,0x71,0xD4,0x95,0xC8,0xAE,0x63,0x2E,0xA4,0xB3,0x95,0xD3,0x10,0x25,0xB1,0xA2,0x5A,0x0E, -0x04,0x9F,0x90,0x2F,0x52,0x1A,0xB8,0x4C,0x0C,0xCF,0xC2,0x77,0x58,0xDA,0x9D,0xE4,0xB3,0x29,0xB9,0x05, -0x6F,0x9E,0x12,0x4A,0x38,0xD6,0xFA,0xD9,0xF2,0xA7,0x92,0xCC,0x35,0xBE,0x9B,0xA6,0x28,0xC6,0x99,0xF6, -0x37,0xC9,0x2C,0xA6,0x29,0x8B,0x17,0x75,0x04,0xE4,0xAC,0xD1,0x59,0x2E,0xBF,0xC9,0x93,0x88,0x21,0x10, -0x73,0x25,0x6C,0x94,0xC1,0x34,0x15,0x6E,0x55,0x05,0xD5,0xD2,0xCD,0xB6,0xC0,0x2D,0x5B,0x6E,0xBD,0xB5, -0x53,0xBB,0x6E,0x57,0xCE,0x15,0xC1,0xBE,0xA9,0xFA,0x46,0x3C,0x68,0xC4,0xBA,0x6F,0x38,0xA8,0x74,0xFD, -0xE2,0x6A,0x11,0x15,0x19,0x6A,0x06,0x54,0x94,0xEE,0xEF,0x3A,0x8D,0x50,0x01,0xF3,0x96,0xDF,0x60,0x99, -0xE6,0xAD,0x6F,0x92,0x14,0x76,0x03,0xCF,0xBF,0x42,0xB3,0x92,0xA9,0x4D,0x1B,0x68,0x56,0xE9,0x4E,0x89, -0x50,0xE7,0x3C,0xC9,0x6B,0x45,0x7A,0x55,0x2A,0x00,0x57,0xDC,0x3C,0x12,0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06,0x7D,0xB5,0xF2,0xCF,0x24, -0xC2,0x17,0x85,0xCB,0x89,0x85,0x6A,0x6A,0x3D,0x83,0x9C,0x85,0xA0,0x48,0xF3,0x07,0xE3,0x74,0xA4,0x19, -0x1F,0x7F,0xEC,0x3E,0xB9,0xFA,0xD2,0xFF,0xE8,0x74,0xFB,0x57,0xE6,0xEF,0x66,0x8F,0xD8,0x1C,0x67,0xDC, -0xA0,0xE8,0x86,0xCC,0x10,0xD8,0xB9,0x2D,0xF2,0xED,0x70,0x06,0x52,0x98,0x83,0x6A,0x0D,0xA2,0xD8,0xDB, -0x72,0x9C,0x0D,0x0F,0x1F,0xA0,0x08,0x03,0xEB,0xFA,0xC9,0xF9,0xF9,0xE9,0xF9,0x47,0xBD,0x83,0x3B,0xFA, -0x95,0xAB,0xE9,0x1D,0x6A,0xBA,0xDC,0x86,0xA2,0x33,0xC5,0x59,0x78,0x86,0x78,0x68,0x04,0xF6,0x0D,0x8A, -0x72,0xD0,0x85,0x60,0x84,0x79,0xA0,0x38,0x7D,0x92,0x73,0xCE,0xA8,0x6E,0x0E,0x98,0x4D,0x28,0xC5,0xE9, -0xB3,0xF1,0xEB,0x57,0x9E,0x7E,0xCE,0x18,0xD7,0x8E,0x49,0xAA,0x5B,0x72,0x37,0x6C,0x94,0x24,0x98,0x06, -0x47,0x21,0x89,0x02,0x83,0x99,0x03,0x81,0xEE,0x4B,0x74,0x59,0x88,0x00,0xB6,0x6F,0xAB,0x92,0x75,0x0A, -0x52,0xEB,0x96,0x6F,0xC7,0x79,0xC4,0x49,0x12,0x61,0x6F,0xA3,0x0F,0x3D,0x8A,0x62,0x80,0x89,0x34,0x2C, -0x60,0x24,0xF0,0x74,0x15,0x8C,0x8A,0x10,0xB6,0x6E,0x15,0x5F,0xAD,0x12,0xB4,0x56,0x09,0x9A,0xB8,0x09, -0x48,0xA4,0x5B,0x81,0x5D,0xD7,0xCA,0xD0,0x2B,0x96,0x2A,0x61,0x01,0x9E,0x22,0xE0,0xE4,0x9D,0x90,0x1A, -0x4A,0xEF,0x75,0x0B,0x05,0x6A,0xA1,0xAC,0xAD,0x8D,0xAC,0xA9,0x0D,0xB5,0x8D,0xEB,0x90,0x33,0x85,0x9C, -0xB6,0x91,0xD3,0x26,0xF2,0x91,0xB4,0x86,0x75,0xC8,0xA9,0x42,0x8E,0x5A,0x22,0x46,0x52,0x44,0x15,0xE1, -0xBA,0x42,0x9B,0x20,0x10,0x60,0x47,0x4D,0x31,0xA1,0x07,0x0E,0x89,0x26,0x11,0x0E,0xBC,0x0D,0x07,0x7A, -0xA2,0xA8,0xF6,0xB6,0x9C,0x35,0x6B,0x44,0x6A,0x8D,0xBC,0xB5,0x46,0x2E,0xD7,0x20,0x09,0x28,0x11,0xF2, -0x86,0x6E,0xE5,0x52,0x6B,0xED,0x11,0xB5,0x9C,0x1F,0x62,0xFF,0x7A,0xC2,0xE4,0x88,0x6C,0x8B,0x15,0x37, -0x90,0xA4,0x99,0x48,0x9A,0xF2,0x28,0x02,0x34,0x13,0x1B,0xBC,0xDC,0x13,0x94,0xAD,0xA4,0x29,0xBE,0x36, -0x8C,0xB8,0xAD,0x4B,0x84,0xB8,0xAD,0xA5,0xB8,0x35,0x6D,0x84,0x6E,0xB0,0xB6,0x4E,0x4B,0xB1,0xB9,0x66, -0x30,0x59,0x37,0x98,0x9B,0x56,0x6A,0x33,0xEA,0x47,0xC4,0xBF,0xF6,0x6A,0x37,0x36,0x17,0x46,0xB3,0x23, -0x38,0xE1,0x1E,0xC5,0x73,0xED,0x67,0x08,0x4B,0xC7,0x88,0xA3,0x01,0x2F,0xC8,0x18,0x85,0xDD,0x60,0x20, -0x04,0xA7,0x51,0xF0,0xC2,0xCC,0x46,0x01,0x0C,0x9F,0x5D,0x8C,0x75,0x4B,0xEF,0x89,0x5D,0xD1,0xC1,0x93, -0x89,0xB9,0x34,0x2B,0x5F,0xB2,0xA8,0x8C,0xEA,0x17,0x69,0x54,0x0F,0x41,0xA3,0xB4,0xB8,0xA5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,0x54,0x9C,0x98,0x40,0x43, -0x79,0x8B,0x47,0x6C,0x8B,0x0B,0x1E,0xD0,0xDB,0xB1,0x3A,0x20,0x42,0x79,0x8D,0xC1,0x5A,0x58,0x72,0x96, -0xB2,0x04,0xCD,0x90,0x98,0x07,0x63,0xE0,0x60,0x92,0xB8,0xA0,0xD6,0xA8,0x88,0xEA,0xEB,0x86,0x6E,0xDF, -0x03,0x7B,0x95,0x97,0x39,0xA7,0x53,0x03,0x6A,0x27,0xB3,0x9E,0x16,0xFC,0x77,0x49,0x88,0xDF,0xF2,0x22, -0xBB,0x84,0x3C,0xAE,0x5B,0x51,0xD1,0xFC,0x94,0x15,0x0D,0x3F,0x2B,0x5B,0xB7,0x0D,0x20,0xA3,0x25,0x98, -0xD1,0x69,0xD1,0x24,0x94,0x94,0x74,0x4A,0x60,0xF9,0x4C,0x92,0x32,0x93,0x85,0x65,0x2B,0xC4,0xB7,0x15, -0x1E,0xAB,0xF2,0x1C,0x5E,0x97,0xE7,0xEA,0x5B,0x96,0xFF,0x4E,0xFC,0x84,0xCE,0x4A,0x61,0x92,0xB2,0x35, -0x23,0xA5,0x28,0x93,0x38,0xF9,0x2A,0x23,0xE9,0xBF,0x3D,0xF5,0x1D,0x9F,0xBC,0x3A,0x19,0x9F,0x34,0x0F, -0x00,0xCD,0xCB,0x21,0xFE,0x57,0xB7,0x2F,0xDC,0x74,0x8D,0xBF,0x91,0xD4,0xA0,0xEC,0x36,0xCD,0xD6,0xFD, -0x51,0xD4,0xBA,0x97,0xAA,0x33,0x4A,0x71,0xE1,0x03,0x7A,0xDA,0xDC,0x6C,0x30,0x22,0xC7,0xEB,0x3B,0x2D, -0x6A,0xE9,0xAA,0x0A,0x97,0x5E,0x8D,0x1E,0x2A,0x57,0x91,0x59,0x1D,0x08,0x89,0x47,0x8B,0x88,0x62,0x89, -0xB3,0x21,0xD9,0xF7,0xE1,0x50,0xD8,0x31,0xD5,0x5D,0x8E,0xE7,0xC1,0xB5,0x97,0x7F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C,0xBC,0x98,0x01,0x37,0x6F,0xF4,0x74, -0x30,0x88,0x0C,0xCC,0x10,0xA3,0x74,0x24,0xEE,0x00,0x54,0x22,0x59,0xAA,0x0D,0xF4,0xA4,0xEB,0x1A,0xA0, -0xB1,0x9E,0x4C,0x19,0x36,0xE8,0x01,0xE6,0x57,0x40,0x0A,0x40,0xEA,0x31,0x20,0xD9,0x18,0x44,0x30,0x88, -0x3C,0x3D,0x66,0x94,0x5D,0x23,0xD2,0x9C,0x4E,0x00,0x42,0x8A,0xAF,0x04,0xF4,0x0E,0xB5,0x8A,0x7D,0x90, -0x84,0x6A,0x88,0xDA,0x7D,0xB3,0xB8,0xE5,0xAC,0xEF,0x98,0x70,0xE9,0x36,0x85,0x7D,0x6C,0x48,0xB4,0x4C, -0x14,0x1E,0x23,0x9C,0x65,0x92,0x6F,0x21,0xD7,0x6B,0x16,0x80,0x58,0x80,0xD6,0x8B,0xA1,0x25,0x16,0x02, -0x09,0x05,0x60,0x1C,0xE2,0xB8,0x80,0x70,0x68,0x0A,0x10,0x12,0xA0,0x6F,0xA5,0xAA,0x46,0xB2,0xC0,0x23, -0x74,0xE6,0xF5,0x7B,0x8E,0xB5,0x4A,0xF6,0x22,0xC3,0x23,0x36,0xE5,0x63,0x34,0xC9,0x8C,0x0D,0xC7,0x5C, -0x9D,0x21,0x40,0x23,0x88,0x26,0xC6,0x96,0xB9,0x1E,0xFD,0x3D,0x4B,0xAF,0x71,0x5A,0x20,0x8B,0xCA,0x0C, -0x0A,0xB3,0x08,0x7E,0xF9,0xD0,0x17,0x2F,0xFA,0x5F,0x11,0x8A,0x6B,0xE0,0x28,0x64,0xF3,0xB3,0x94,0x50, -0xFE,0x5A,0x1E,0xFA,0x8D,0x8D,0xBE,0xDC,0x27,0x75,0x17,0x25,0x23,0x50,0x79,0x49,0xB5,0x10,0xC1,0xCC, -0x6D,0x5D,0x55,0x59,0x13,0xD8,0x2E,0x88,0xAD,0xEE,0x62,0x4E,0xA8,0xAB,0x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,0xAA,0x03,0xBD,0x7E,0xA4,0x57, -0x1E,0x5A,0x42,0x08,0x6B,0xA6,0xC2,0x2A,0xB0,0x5A,0x58,0x5E,0x69,0xC2,0x43,0x7C,0x04,0x06,0x0F,0x19, -0x3B,0x60,0x36,0xF5,0x1A,0x37,0x8D,0x3A,0x87,0xBF,0x3A,0x84,0xED,0x41,0xC1,0x56,0x80,0xA7,0x84,0x62, -0x19,0xBD,0x54,0xD3,0x2A,0x00,0x42,0x0D,0x24,0x95,0x90,0xB2,0x6D,0x89,0xB6,0xC8,0x7E,0x64,0x26,0x14, -0x69,0xE8,0xE2,0x83,0x0F,0x91,0xE8,0x75,0x99,0xB0,0x57,0xC0,0x73,0x19,0x48,0x1A,0x13,0xD6,0xBC,0xC0, -0xD3,0xF3,0xA2,0xA5,0x83,0x94,0xBC,0x11,0x84,0x95,0x38,0x10,0x6F,0x55,0xE3,0x5E,0x68,0xAF,0x4F,0x3D, -0x0A,0x6C,0x2E,0xC1,0xC5,0x94,0x00,0x81,0x5E,0xA5,0xF3,0x5F,0x5E,0xBF,0x7A,0xC6,0x79,0x72,0xAE,0x76, -0x14,0x68,0xB5,0x07,0x6A,0x43,0x33,0x17,0x3C,0xBD,0x2B,0x0B,0x43,0x11,0x28,0x54,0xA8,0xFB,0xE5,0x74, -0xF2,0x09,0xFB,0x20,0xC9,0xEB,0x0C,0x72,0xE8,0x96,0x2D,0xD0,0xC7,0xE3,0x33,0x7B,0xD7,0x76,0xA0,0x52, -0x81,0xFD,0xF4,0x43,0x61,0x31,0xCB,0x7F,0x84,0xBC,0xFD,0xCF,0x90,0x09,0xC4,0xFB,0x0C,0x02,0x7A,0x89, -0xDF,0xC6,0x0D,0x53,0x36,0x97,0x68,0x27,0x69,0x2A,0x8C,0x61,0x1C,0x92,0x4C,0x9B,0xC0,0x60,0x86,0x53, -0x2D,0x60,0x38,0xD3,0x28,0xE3,0x5A,0x96,0x27,0x09,0x4B,0xF9,0x3D,0x7D,0xD8,0x7A,0x79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