-
Notifications
You must be signed in to change notification settings - Fork 7.7k
feat(webserver): add support for chunked HTTP responses Fixes #5080 #11894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
me-no-dev
merged 6 commits into
espressif:master
from
ritesh006:feature/chunked-response
Oct 6, 2025
+159
−0
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f4f8762
Add chunkedResponseModeStart, sendChunk, chunkedResponseFinalize
ritesh006 3d65e97
Merge branch 'master' into feature/chunked-response
ritesh006 c1b8036
feat(webserver): Chunk example for ESP32 HTTP server
SuGlider 0310c97
feat(webserver): Add ci.json for ChunkWriting example configuration
SuGlider 078e882
fix(example): not necessary code line
SuGlider dfaa04b
ci(pre-commit): Apply automatic fixes
pre-commit-ci-lite[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
libraries/WebServer/examples/ChunkWriting/ChunkWriting.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* This example demonstrates how to send an HTTP response using chunks | ||
* It will create an HTTP Server (port 80) associated with an a MDNS service | ||
* Access the HTTP server using a Web Browser: | ||
* URL can be composed using the MDNS name "esp32_chunk_resp.local" | ||
* http://esp32_chunk_resp.local/ | ||
* or the IP Address that will be printed out, such as for instance 192.168.1.10 | ||
* http://192.168.1.10/ | ||
* | ||
* ESP32 Server response can also be viewed using the curl command: | ||
* curl -i esp32_chunk_resp.local:80 | ||
* curl -i --raw esp32_chunk_resp.local:80 | ||
*/ | ||
|
||
#include <WiFi.h> | ||
#include <NetworkClient.h> | ||
#include <WebServer.h> | ||
#include <ESPmDNS.h> | ||
|
||
const char *ssid = "........"; | ||
const char *password = "........"; | ||
|
||
WebServer server(80); | ||
|
||
void handleChunks() { | ||
uint8_t countDown = 10; | ||
server.chunkResponseBegin(); | ||
char countContent[8]; | ||
while (countDown) { | ||
sprintf(countContent, "%d...\r\n", countDown--); | ||
server.chunkWrite(countContent, strlen(countContent)); | ||
// count down shall show up in the browser only after about 5 seconds when finishing the whole transmission | ||
// using "curl -i esp32_chunk_resp.local:80", it will show the count down as it sends each chunk | ||
delay(500); | ||
} | ||
server.chunkWrite("DONE!", 5); | ||
server.chunkResponseEnd(); | ||
} | ||
|
||
void setup(void) { | ||
Serial.begin(115200); | ||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(ssid, password); | ||
Serial.println(""); | ||
|
||
// Wait for connection | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
Serial.println(""); | ||
Serial.print("Connected to "); | ||
Serial.println(ssid); | ||
Serial.print("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
|
||
// Use the URL: http://esp32_chunk_resp.local/ | ||
if (MDNS.begin("esp32_chunk_resp")) { | ||
Serial.println("MDNS responder started"); | ||
} | ||
|
||
server.on("/", handleChunks); | ||
|
||
server.onNotFound([]() { | ||
server.send(404, "text/plain", "Page not found"); | ||
}); | ||
|
||
server.begin(); | ||
Serial.println("HTTP server started"); | ||
} | ||
|
||
void loop(void) { | ||
server.handleClient(); | ||
delay(2); //allow the cpu to switch to other tasks | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"requires_any": [ | ||
"CONFIG_SOC_WIFI_SUPPORTED=y", | ||
"CONFIG_ESP_WIFI_REMOTE_ENABLED=y" | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.