diff options
| author | schererleander <leander@schererleander.de> | 2026-01-20 08:34:54 +0100 |
|---|---|---|
| committer | schererleander <leander@schererleander.de> | 2026-01-20 08:34:54 +0100 |
| commit | 85ea4e995a75abe061f6fc375ea0481084dddd43 (patch) | |
| tree | 7eb5d57653ecd8f041aeac4e68d7d554c1168681 /libraries/ESP_Async_WebServer/examples/ResumableDownload/ResumableDownload.ino | |
Diffstat (limited to 'libraries/ESP_Async_WebServer/examples/ResumableDownload/ResumableDownload.ino')
| -rw-r--r-- | libraries/ESP_Async_WebServer/examples/ResumableDownload/ResumableDownload.ino | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/libraries/ESP_Async_WebServer/examples/ResumableDownload/ResumableDownload.ino b/libraries/ESP_Async_WebServer/examples/ResumableDownload/ResumableDownload.ino new file mode 100644 index 0000000..373ca24 --- /dev/null +++ b/libraries/ESP_Async_WebServer/examples/ResumableDownload/ResumableDownload.ino @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright 2016-2025 Hristo Gochkov, Mathieu Carbou, Emil Muratov + +// +// Make sure resumable downloads can be implemented (HEAD request / response and Range header) +// + +#include <Arduino.h> +#ifdef ESP32 +#include <AsyncTCP.h> +#include <WiFi.h> +#elif defined(ESP8266) +#include <ESP8266WiFi.h> +#include <ESPAsyncTCP.h> +#elif defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350) +#include <RPAsyncTCP.h> +#include <WiFi.h> +#endif + +#include <ESPAsyncWebServer.h> + +static AsyncWebServer server(80); + +void setup() { + Serial.begin(115200); + +#ifndef CONFIG_IDF_TARGET_ESP32H2 + WiFi.mode(WIFI_AP); + WiFi.softAP("esp-captive"); +#endif + + /* + ❯ curl -I -X HEAD http://192.168.4.1/download + HTTP/1.1 200 OK + Content-Length: 1024 + Content-Type: application/octet-stream + Connection: close + Accept-Ranges: bytes + */ + // Ref: https://github.com/mathieucarbou/ESPAsyncWebServer/pull/80 + server.on("/download", HTTP_HEAD | HTTP_GET, [](AsyncWebServerRequest *request) { + if (request->method() == HTTP_HEAD) { + AsyncWebServerResponse *response = request->beginResponse(200, "application/octet-stream"); + response->addHeader(asyncsrv::T_Accept_Ranges, "bytes"); + response->addHeader(asyncsrv::T_Content_Length, 10); + response->setContentLength(1024); // make sure we can overrides previously set content length + response->addHeader(asyncsrv::T_Content_Type, "foo"); + response->setContentType("application/octet-stream"); // make sure we can overrides previously set content type + // ... + request->send(response); + } else { + // ... + } + }); + + server.begin(); +} + +void loop() { + delay(100); +} |
