Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 373bcc0

Browse files
committed
Code and CI cleanup in relation to regex support
1 parent b18bfeb commit 373bcc0

File tree

7 files changed

+121
-120
lines changed

7 files changed

+121
-120
lines changed

.github/workflows/build-esp32.yml

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -170,64 +170,19 @@ jobs:
170170
PLATFORMIO_SRC_DIR=examples/$i PIO_BOARD=${{ matrix.board }} pio run -e ci-arduino-3
171171
done
172172
173-
platformio-esp32-arduino-latest:
174-
name: ESP32 (pio) - Arduino Latest
175-
runs-on: ubuntu-latest
176-
strategy:
177-
fail-fast: false
178-
matrix:
179-
board:
180-
- esp32dev
181-
- esp32-s2-saola-1
182-
- esp32-s3-devkitc-1
183-
- esp32-c3-devkitc-02
184-
- esp32-c6-devkitc-1
185-
- esp32-h2-devkitm-1
186-
187-
steps:
188-
- name: Checkout
189-
uses: actions/checkout@v5
190-
191-
# - name: Cache PlatformIO
192-
# uses: actions/cache@v4
193-
# with:
194-
# key: ${{ runner.os }}-pio
195-
# path: |
196-
# ~/.cache/pip
197-
# ~/.platformio
198-
199-
- name: Python
200-
uses: actions/setup-python@v6
201-
with:
202-
python-version: "3.x"
203-
204-
- name: Install PIO
205-
run: |
206-
python -m pip install --upgrade pip
207-
pip install --upgrade platformio
208-
pip install --upgrade intelhex
209-
pip install --upgrade rich_click
210-
211-
- name: Build Examples
212-
run: |
213-
for i in `ls examples`; do
214-
echo "============================================================="
215-
echo "Building examples/$i..."
216-
echo "============================================================="
217-
PLATFORMIO_SRC_DIR=examples/$i PIO_BOARD=${{ matrix.board }} pio run -e ci-arduino-rc
218-
done
219-
220173
platformio-specific-envs:
221174
name: ESP32 (pio) - Specific Envs
222175
runs-on: ubuntu-latest
223176
strategy:
224177
fail-fast: false
225178
matrix:
226179
env:
227-
- ci-arduino-rc-asynctcp
228-
- ci-arduino-3-no-json
180+
- ci-latest-asynctcp
181+
- ci-no-json
182+
- ci-no-chunk-inflight
229183
- ci-arduino-2-esp-idf-log
230184
- ci-arduino-3-esp-idf-log
185+
- ci-regex
231186

232187
steps:
233188
- name: Checkout

examples/UriMatcher/UriMatcher.ino

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: LGPL-3.0-or-later
2+
// Copyright 2016-2025 Hristo Gochkov, Mathieu Carbou, Emil Muratov
3+
4+
//
5+
// Shows how to serve a static file
6+
//
7+
8+
#include <Arduino.h>
9+
#if defined(ESP32) || defined(LIBRETINY)
10+
#include <AsyncTCP.h>
11+
#include <WiFi.h>
12+
#elif defined(ESP8266)
13+
#include <ESP8266WiFi.h>
14+
#include <ESPAsyncTCP.h>
15+
#elif defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350)
16+
#include <RPAsyncTCP.h>
17+
#include <WiFi.h>
18+
#endif
19+
20+
#include <ESPAsyncWebServer.h>
21+
#include <LittleFS.h>
22+
23+
static AsyncWebServer server(80);
24+
25+
void setup() {
26+
Serial.begin(115200);
27+
28+
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED || LT_ARD_HAS_WIFI
29+
WiFi.mode(WIFI_AP);
30+
WiFi.softAP("esp-captive");
31+
#endif
32+
33+
// curl -v http://192.168.4.1/
34+
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
35+
request->send(200, "text/plain", "Hello, world");
36+
});
37+
38+
server.begin();
39+
}
40+
41+
// not needed
42+
void loop() {
43+
delay(100);
44+
}

platformio.ini

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ build_flags =
5151
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=64
5252
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1
5353
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096
54+
; -D ASYNCWEBSERVER_REGEX=1
5455
; -D CONFIG_ASYNC_TCP_USE_WDT=0
5556
; -D CONFIG_ARDUHAL_LOG_COLORS
5657
; -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
@@ -72,33 +73,15 @@ lib_deps =
7273
board_build.partitions = partitions-4MB.csv
7374
board_build.filesystem = littlefs
7475

76+
; PLATFORMS (ESP32, ESP8266, Raspberry, LibreTiny)
77+
7578
[env:arduino-2]
7679
7780

7881
[env:arduino-3]
7982
; board = esp32-p4
8083
; board = esp32-h2-devkitm-1
8184

82-
[env:arduino-rc]
83-
platform = https://github.com/pioarduino/platform-espressif32/releases/download/54.03.20-rc2/platform-espressif32.zip
84-
85-
[env:arduino-3-no-json]
86-
lib_deps =
87-
ESP32Async/AsyncTCP @ 3.4.9
88-
89-
[env:arduino-rc-asynctcp]
90-
lib_deps =
91-
https://github.com/ESP32Async/AsyncTCP
92-
93-
[env:arduino-3-no-chunk-inflight]
94-
build_flags = ${env.build_flags}
95-
-D ASYNCWEBSERVER_USE_CHUNK_INFLIGHT=0
96-
97-
[env:AsyncTCPSock]
98-
lib_deps =
99-
https://github.com/ESP32Async/AsyncTCPSock/archive/refs/tags/v1.0.3-dev.zip
100-
build_flags = ${env.build_flags}
101-
10285
[env:esp8266]
10386
platform = espressif8266
10487
; board = huzzah
@@ -130,46 +113,49 @@ lib_deps =
130113
; (BK7231 already uses it)
131114
custom_versions.freertos = 9.0.0
132115

133-
; CI
134-
135-
[env:ci-arduino-2]
136-
137-
board = ${sysenv.PIO_BOARD}
138-
139-
[env:ci-arduino-3]
140-
board = ${sysenv.PIO_BOARD}
116+
; SPECIFIC ENVS (for testing various configurations)
141117

142-
[env:ci-arduino-rc]
143-
platform = https://github.com/pioarduino/platform-espressif32/releases/download/54.03.20-rc2/platform-espressif32.zip
144-
board = ${sysenv.PIO_BOARD}
145-
146-
[env:ci-arduino-2-esp-idf-log]
118+
[env:arduino-2-esp-idf-log]
147119
148-
board = ${sysenv.PIO_BOARD}
149120
build_flags =
150121
${env.build_flags}
151122
-D USE_ESP_IDF_LOG=1
152123
-D TAG=\"core\"
153124

154-
[env:ci-arduino-3-esp-idf-log]
155-
board = ${sysenv.PIO_BOARD}
125+
[env:arduino-3-esp-idf-log]
156126
build_flags =
157127
${env.build_flags}
158128
-D USE_ESP_IDF_LOG=1
159129

160-
[env:ci-arduino-3-no-json]
161-
board = ${sysenv.PIO_BOARD}
130+
[env:no-json]
162131
lib_deps =
163132
ESP32Async/AsyncTCP @ 3.4.9
164133

165-
[env:ci-arduino-rc-asynctcp]
134+
[env:latest-asynctcp]
166135
lib_deps =
167136
https://github.com/ESP32Async/AsyncTCP
168137

169-
[env:ci-arduino-3-no-chunk-inflight]
170-
board = ${sysenv.PIO_BOARD}
138+
[env:no-chunk-inflight]
171139
build_flags = ${env.build_flags}
172-
-D ASYNCWEBSERVER_USE_CHUNK_INFLIGHT=1
140+
-D ASYNCWEBSERVER_USE_CHUNK_INFLIGHT=0
141+
142+
[env:regex]
143+
build_flags = ${env.build_flags}
144+
-D ASYNCWEBSERVER_REGEX=1
145+
146+
[env:AsyncTCPSock]
147+
lib_deps =
148+
https://github.com/ESP32Async/AsyncTCPSock/archive/refs/tags/v1.0.3-dev.zip
149+
build_flags = ${env.build_flags}
150+
151+
; PLATFORM CI (ESP32, ESP8266, Raspberry, LibreTiny)
152+
153+
[env:ci-arduino-2]
154+
155+
board = ${sysenv.PIO_BOARD}
156+
157+
[env:ci-arduino-3]
158+
board = ${sysenv.PIO_BOARD}
173159

174160
[env:ci-esp8266]
175161
platform = espressif8266
@@ -199,3 +185,33 @@ lib_deps =
199185
DNSServer
200186
ESP32Async/AsyncTCP @ 3.4.3
201187
custom_versions.freertos = 9.0.0
188+
189+
; CI FOR SPECIFIC CONFIGURATIONS
190+
191+
[env:ci-arduino-2-esp-idf-log]
192+
193+
build_flags =
194+
${env.build_flags}
195+
-D USE_ESP_IDF_LOG=1
196+
-D TAG=\"core\"
197+
198+
[env:ci-arduino-3-esp-idf-log]
199+
build_flags =
200+
${env.build_flags}
201+
-D USE_ESP_IDF_LOG=1
202+
203+
[env:ci-no-json]
204+
lib_deps =
205+
ESP32Async/AsyncTCP @ 3.4.9
206+
207+
[env:ci-latest-asynctcp]
208+
lib_deps =
209+
https://github.com/ESP32Async/AsyncTCP
210+
211+
[env:ci-no-chunk-inflight]
212+
build_flags = ${env.build_flags}
213+
-D ASYNCWEBSERVER_USE_CHUNK_INFLIGHT=1
214+
215+
[env:ci-regex]
216+
build_flags = ${env.build_flags}
217+
-D ASYNCWEBSERVER_REGEX=1

src/ESPAsyncWebServer.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@
5050
#define ASYNCWEBSERVER_FORK_ESP32Async
5151

5252
#ifdef ASYNCWEBSERVER_REGEX
53-
#define ASYNCWEBSERVER_REGEX_ATTRIBUTE
54-
#else
55-
#define ASYNCWEBSERVER_REGEX_ATTRIBUTE __attribute__((warning("ASYNCWEBSERVER_REGEX not defined")))
53+
#include <regex>
5654
#endif
5755

5856
// See https://github.com/ESP32Async/ESPAsyncWebServer/commit/3d3456e9e81502a477f6498c44d0691499dda8f9#diff-646b25b11691c11dce25529e3abce843f0ba4bd07ab75ec9eee7e72b06dbf13fR388-R392
@@ -254,7 +252,9 @@ class AsyncWebServerRequest {
254252

255253
std::list<AsyncWebHeader> _headers;
256254
std::list<AsyncWebParameter> _params;
255+
#ifdef ASYNCWEBSERVER_REGEX
257256
std::list<String> _pathParams;
257+
#endif
258258

259259
std::unordered_map<const char *, String, std::hash<const char *>, std::equal_to<const char *>> _attributes;
260260

@@ -277,8 +277,6 @@ class AsyncWebServerRequest {
277277
void _onDisconnect();
278278
void _onData(void *buf, size_t len);
279279

280-
void _addPathParam(const char *param);
281-
282280
bool _parseReqHead();
283281
bool _parseReqHeader();
284282
void _parseLine();
@@ -615,10 +613,19 @@ class AsyncWebServerRequest {
615613
bool hasArg(const __FlashStringHelper *data) const; // check if F(argument) exists
616614
#endif
617615

618-
const String &ASYNCWEBSERVER_REGEX_ATTRIBUTE pathArg(size_t i) const;
619-
const String &ASYNCWEBSERVER_REGEX_ATTRIBUTE pathArg(int i) const {
616+
#ifdef ASYNCWEBSERVER_REGEX
617+
const String &pathArg(size_t i) const {
618+
if (i >= _pathParams.size()) {
619+
return emptyString;
620+
}
621+
auto it = _pathParams.begin();
622+
std::advance(it, i);
623+
return *it;
624+
}
625+
const String &pathArg(int i) const {
620626
return i < 0 ? emptyString : pathArg((size_t)i);
621627
}
628+
#endif
622629

623630
// get request header value by name
624631
const String &header(const char *name) const;

src/WebHandlerImpl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
#define ASYNCWEBSERVERHANDLERIMPL_H_
66

77
#include <string>
8-
#ifdef ASYNCWEBSERVER_REGEX
9-
#include <regex>
10-
#endif
11-
128
#include "stddef.h"
139
#include <time.h>
1410

src/WebHandlers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ bool AsyncCallbackWebHandler::canHandle(AsyncWebServerRequest *request) const {
312312
std::string s(request->url().c_str());
313313
if (std::regex_search(s, matches, pattern)) {
314314
for (size_t i = 1; i < matches.size(); ++i) { // start from 1
315-
request->_addPathParam(matches[i].str().c_str());
315+
request->_pathParams.emplace_back(matches[i].str().c_str());
316316
}
317317
} else {
318318
return false;

src/WebRequest.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ AsyncWebServerRequest::~AsyncWebServerRequest() {
9090

9191
_this.reset();
9292

93-
_headers.clear();
94-
95-
_pathParams.clear();
96-
9793
AsyncWebServerResponse *r = _response;
9894
_response = NULL;
9995
delete r;
@@ -271,10 +267,6 @@ void AsyncWebServerRequest::_onDisconnect() {
271267
_server->_handleDisconnect(this);
272268
}
273269

274-
void AsyncWebServerRequest::_addPathParam(const char *p) {
275-
_pathParams.emplace_back(p);
276-
}
277-
278270
void AsyncWebServerRequest::_addGetParams(const String &params) {
279271
size_t start = 0;
280272
while (start < params.length()) {
@@ -1075,15 +1067,6 @@ const String &AsyncWebServerRequest::argName(size_t i) const {
10751067
return getParam(i)->name();
10761068
}
10771069

1078-
const String &AsyncWebServerRequest::pathArg(size_t i) const {
1079-
if (i >= _pathParams.size()) {
1080-
return emptyString;
1081-
}
1082-
auto it = _pathParams.begin();
1083-
std::advance(it, i);
1084-
return *it;
1085-
}
1086-
10871070
const String &AsyncWebServerRequest::header(const char *name) const {
10881071
const AsyncWebHeader *h = getHeader(name);
10891072
return h ? h->value() : emptyString;

0 commit comments

Comments
 (0)