mirror of
https://github.com/esphome/esphome.git
synced 2026-02-21 08:55:36 -07:00
static, less heap
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user