static, less heap

This commit is contained in:
J. Nick Koston
2026-01-11 09:00:20 -10:00
parent 1fa86a7505
commit d7dd6a5cb8
4 changed files with 8 additions and 1 deletions

View File

@@ -34,6 +34,8 @@ async def to_code(config):
cg.add(cg.RawExpression(f"{web_server_base_ns}::global_web_server_base = {var}"))
if CORE.is_esp32:
# Count for StaticVector in web_server_idf - matches headers added in init()
cg.add_define("WEB_SERVER_DEFAULT_HEADERS_COUNT", 1)
return
if CORE.using_arduino:

View File

@@ -100,6 +100,8 @@ class WebServerBase : public Component {
}
this->server_ = std::make_unique<AsyncWebServer>(this->port_);
// All content is controlled and created by user - so allowing all origins is fine here.
// NOTE: Currently 1 header. If more are added, update in __init__.py:
// cg.add_define("WEB_SERVER_DEFAULT_HEADERS_COUNT", 1)
DefaultHeaders::Instance().addHeader(ESPHOME_F("Access-Control-Allow-Origin"), ESPHOME_F("*"));
this->server_->begin();

View File

@@ -2,6 +2,7 @@
#ifdef USE_ESP32
#include "esphome/core/defines.h"
#include "esphome/core/helpers.h"
#include <esp_http_server.h>
#include <atomic>
@@ -345,7 +346,8 @@ class DefaultHeaders {
static DefaultHeaders &Instance();
protected:
std::vector<HttpHeader> headers_;
// Stack-allocated, no reallocation machinery. Count defined in web_server_base where headers are added.
StaticVector<HttpHeader, WEB_SERVER_DEFAULT_HEADERS_COUNT> headers_;
};
} // namespace web_server_idf

View File

@@ -213,6 +213,7 @@
#define USE_WEBSERVER_PORT 80 // NOLINT
#define USE_WEBSERVER_GZIP
#define USE_WEBSERVER_SORTING
#define WEB_SERVER_DEFAULT_HEADERS_COUNT 1
#define USE_CAPTIVE_PORTAL_GZIP
#define USE_WIFI_11KV_SUPPORT
#define USE_WIFI_FAST_CONNECT