Skip to content

Commit 181392f

Browse files
authored
Merge pull request #17 from playmiel/dev
1.1.3
2 parents 40e22e3 + 1c6c1e2 commit 181392f

19 files changed

Lines changed: 695 additions & 115 deletions

File tree

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ An asynchronous HTTP client library for ESP32 microcontrollers, built on top of
2323
-**Multiple simultaneous requests** - Handle multiple requests concurrently
2424
-**Chunked transfer decoding** - Validates framing and exposes parsed trailers
2525
-**Optional redirect following** - Follow 301/302/303 (converted to GET) and 307/308 (method preserved)
26-
-**Header & body guards** - Limit buffered response headers/body to avoid runaway responses
26+
-**Header & body guards** - Limits buffered headers (~2.8 KiB) and body (8 KiB) by default to avoid runaway responses
2727
-**Zero-copy streaming** - Combine `req->setNoStoreBody(true)` with `client.onBodyChunk(...)` to stream large payloads without heap spikes
2828

2929
> ⚠ Limitations: provide trust material for HTTPS (CA, fingerprint or insecure flag) and remember the full body is buffered in memory unless you opt into zero-copy streaming via `setNoStoreBody(true)`.
@@ -150,10 +150,10 @@ void setDefaultConnectTimeout(uint32_t ms);
150150
// Follow HTTP redirects (max hops clamps to >=1). Disabled by default.
151151
void setFollowRedirects(bool enable, uint8_t maxHops = 3);
152152
153-
// Abort if response headers exceed this many bytes (0 = unlimited)
153+
// Abort if response headers exceed this many bytes (default ~2.8 KiB, 0 = unlimited)
154154
void setMaxHeaderBytes(size_t maxBytes);
155155
156-
// Soft limit for buffered response bodies (bytes, 0 = unlimited)
156+
// Soft limit for buffered response bodies (default 8192 bytes, 0 = unlimited)
157157
void setMaxBodySize(size_t maxBytes);
158158
159159
// Limit simultaneous active requests (0 = unlimited, others queued)
@@ -162,12 +162,20 @@ void setMaxParallel(uint16_t maxParallel);
162162
// Set User-Agent string
163163
void setUserAgent(const char* userAgent);
164164
165+
// Keep-alive connection pooling (idle timeout in ms, clamped to >= 1000)
166+
void setKeepAlive(bool enable, uint16_t idleMs = 5000);
167+
165168
// Cookie jar helpers
166169
void clearCookies();
167170
void setCookie(const char* name, const char* value, const char* path = "/", const char* domain = nullptr,
168171
bool secure = false);
169172
```
170173

174+
Cookies are captured automatically from `Set-Cookie` responses and replayed on matching hosts/paths; call
175+
`clearCookies()` to wipe the jar or `setCookie()` to pre-seed entries manually. Keep-alive pooling is off by default;
176+
enable it with `setKeepAlive(true, idleMs)` to reuse TCP/TLS connections for the same host/port (respecting server
177+
`Connection: close` requests).
178+
171179
#### Callback Types
172180

173181
```cpp
@@ -212,7 +220,7 @@ client.get("http://example.com/chunked", [](AsyncHttpResponse* response) {
212220

213221
```cpp
214222
// Create custom request
215-
AsyncHttpRequest request(HTTP_POST, "http://example.com/api");
223+
AsyncHttpRequest request(HTTP_METHOD_POST, "http://example.com/api");
216224

217225
// Set headers
218226
request.setHeader("Content-Type", "application/json");
@@ -229,6 +237,11 @@ request.setTimeout(10000);
229237
client.request(&request, onSuccess, onError);
230238
```
231239
240+
HTTP method enums are now prefixed (`HTTP_METHOD_GET`, `HTTP_METHOD_POST`, etc.) to avoid collisions with
241+
`ESPAsyncWebServer`'s `HTTP_GET`/`HTTP_POST` values. Legacy aliases can be re-enabled by defining
242+
`ASYNC_HTTP_ENABLE_LEGACY_METHOD_ALIASES` before including `ESPAsyncWebClient.h` (only do this if you are not also
243+
including `ESPAsyncWebServer.h` in the same translation unit).
244+
232245
## Examples
233246
234247
### Simple GET Request
@@ -274,7 +287,7 @@ client.setHeader("X-API-Key", "your-api-key");
274287
client.setUserAgent("MyDevice/1.0");
275288

276289
// Or set per-request headers
277-
AsyncHttpRequest* request = new AsyncHttpRequest(HTTP_GET, "http://example.com");
290+
AsyncHttpRequest* request = new AsyncHttpRequest(HTTP_METHOD_GET, "http://example.com");
278291
request->setHeader("Authorization", "Bearer token");
279292
client.request(request, onSuccess);
280293
```
@@ -336,7 +349,7 @@ client.setHeader("Accept", "application/json");
336349
### Per-Request Settings
337350

338351
```cpp
339-
AsyncHttpRequest* request = new AsyncHttpRequest(HTTP_POST, url);
352+
AsyncHttpRequest* request = new AsyncHttpRequest(HTTP_METHOD_POST, url);
340353
request->setTimeout(30000); // 30 second timeout for this request
341354
request->setHeader("Content-Type", "application/xml");
342355
request->setBody(xmlData);
@@ -369,7 +382,7 @@ Parameters:
369382
Notes:
370383

371384
- Invoked for every segment (chunk or contiguous data block)
372-
- The full body is still accumulated internally (future option may allow disabling accumulation)
385+
- Unless `req->setNoStoreBody(true)` is enabled, the full body is still accumulated internally
373386
- `final` is invoked just before the success callback
374387
- Keep it lightweight (avoid blocking operations)
375388

@@ -378,7 +391,7 @@ Notes:
378391

379392
If `Content-Length` is present, the response is considered complete once that many bytes have been received. Extra bytes (if a misbehaving server sends more) are ignored. Without `Content-Length`, completion is determined by connection close.
380393

381-
Configure `client.setMaxBodySize(maxBytes)` to abort early when the announced `Content-Length` or accumulated chunk data would exceed `maxBytes`, yielding `MAX_BODY_SIZE_EXCEEDED`. Pass `0` (default) to disable the guard.
394+
Configure `client.setMaxBodySize(maxBytes)` to abort early when the announced `Content-Length` or accumulated chunk data would exceed `maxBytes`, yielding `MAX_BODY_SIZE_EXCEEDED`. Pass `0` to disable the guard (this applies only when buffering the response body in memory).
382395

383396
Likewise, guard against oversized or malicious header blocks via `client.setMaxHeaderBytes(limit)`. When the cumulative response headers exceed `limit` bytes before completion of `\r\n\r\n`, the request aborts with `HEADERS_TOO_LARGE`.
384397

examples/arduino/NoStoreToSD/NoStoreToSD.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static bool beginDownload(const char* url, const char* destinationPath) {
3131

3232
currentPath = destinationPath;
3333

34-
AsyncHttpRequest* request = new AsyncHttpRequest(HTTP_GET, url);
34+
AsyncHttpRequest* request = new AsyncHttpRequest(HTTP_METHOD_GET, url);
3535
request->setNoStoreBody(true); // only stream via onBodyChunk
3636

3737
uint32_t id = client.request(

examples/arduino/StreamingUpload/StreamingUpload.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void setup() {
4747
pattern.total = 10 * 1024;
4848
pattern.sent = 0;
4949

50-
AsyncHttpRequest* req = new AsyncHttpRequest(HTTP_POST, "http://httpbin.org/post");
50+
AsyncHttpRequest* req = new AsyncHttpRequest(HTTP_METHOD_POST, "http://httpbin.org/post");
5151
req->addQueryParam("mode", "stream");
5252
req->addQueryParam("unit", "bytes");
5353
req->finalizeQueryParams();

examples/platformio/CustomHeaders/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void setup() {
4545
delay(5000); // Wait 5 seconds
4646

4747
// Make another request with additional headers using the advanced API
48-
AsyncHttpRequest* customRequest = new AsyncHttpRequest(HTTP_POST, "http://httpbin.org/post");
48+
AsyncHttpRequest* customRequest = new AsyncHttpRequest(HTTP_METHOD_POST, "http://httpbin.org/post");
4949
customRequest->setHeader("Content-Type", "application/json");
5050
customRequest->setHeader("X-Custom-Header", "CustomValue123");
5151
customRequest->setHeader("Accept", "application/json");

examples/platformio/StreamingUpload/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void setup() {
6060
pattern.total = 10 * 1024; // 10 KB synthetic
6161
pattern.sent = 0;
6262

63-
AsyncHttpRequest* req = new AsyncHttpRequest(HTTP_POST, "http://httpbin.org/post");
63+
AsyncHttpRequest* req = new AsyncHttpRequest(HTTP_METHOD_POST, "http://httpbin.org/post");
6464
req->addQueryParam("mode", "stream");
6565
req->addQueryParam("unit", "bytes");
6666
req->finalizeQueryParams();

0 commit comments

Comments
 (0)