forked from me-no-dev/ESPAsyncWebServer
-
Notifications
You must be signed in to change notification settings - Fork 70
Add the option to add multiple headers with the same name #48
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
Merged
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
| // Copyright 2016-2025 Hristo Gochkov, Mathieu Carbou, Emil Muratov | ||
|
|
||
| // | ||
| // Query and send headers | ||
| // | ||
|
|
||
| #include <Arduino.h> | ||
| #ifdef ESP32 | ||
| #include <AsyncTCP.h> | ||
| #include <WiFi.h> | ||
| #elif defined(ESP8266) | ||
| #include <ESP8266WiFi.h> | ||
| #include <ESPAsyncTCP.h> | ||
| #elif defined(TARGET_RP2040) | ||
| #include <WebServer.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 -v http://192.168.4.1 | ||
| // | ||
| server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { | ||
| //List all collected headers | ||
| int headers = request->headers(); | ||
| int i; | ||
| for (i = 0; i < headers; i++) { | ||
| const AsyncWebHeader *h = request->getHeader(i); | ||
| Serial.printf("HEADER[%s]: %s\n", h->name().c_str(), h->value().c_str()); | ||
| } | ||
|
|
||
| AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", "Hello World!"); | ||
|
|
||
| //Add header to the response | ||
| response->addHeader("Server", "ESP Async Web Server"); | ||
|
|
||
| //Add multiple headers with the same name | ||
| response->addHeader("Set-Cookie", "sessionId=38afes7a8", false); | ||
| response->addHeader("Set-Cookie", "id=a3fWa; Max-Age=2592000", false); | ||
| response->addHeader("Set-Cookie", "qwerty=219ffwef9w0f; Domain=example.com", false); | ||
|
|
||
| //Remove specific header | ||
| response->removeHeader("Set-Cookie", "sessionId=38afes7a8"); | ||
|
|
||
| //Remove all headers with the same name | ||
| response->removeHeader("Set-Cookie"); | ||
|
|
||
| request->send(response); | ||
| }); | ||
|
|
||
| server.begin(); | ||
| } | ||
|
|
||
| void loop() { | ||
| //Sleep in the loop task to not keep the CPU busy | ||
| delay(1000); | ||
| } |
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
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
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.