[web_server_idf] Replace heap-allocated url() with stack-based url_to() (#13407)

This commit is contained in:
J. Nick Koston
2026-01-28 14:02:19 +13:00
committed by GitHub
parent f084d320fc
commit f9687a2a31
6 changed files with 63 additions and 30 deletions
@@ -32,8 +32,15 @@ class OTARequestHandler : public AsyncWebHandler {
void handleUpload(AsyncWebServerRequest *request, const PlatformString &filename, size_t index, uint8_t *data,
size_t len, bool final) override;
bool canHandle(AsyncWebServerRequest *request) const override {
// Check if this is an OTA update request
bool is_ota_request = request->url() == "/update" && request->method() == HTTP_POST;
if (request->method() != HTTP_POST)
return false;
// Check if this is an OTA update request
#ifdef USE_ESP32
char url_buf[AsyncWebServerRequest::URL_BUF_SIZE];
bool is_ota_request = request->url_to(url_buf) == "/update";
#else
bool is_ota_request = request->url() == ESPHOME_F("/update");
#endif
#if defined(USE_WEBSERVER_OTA_DISABLED) && defined(USE_CAPTIVE_PORTAL)
// IMPORTANT: USE_WEBSERVER_OTA_DISABLED only disables OTA for the web_server component
+14 -4
View File
@@ -2187,7 +2187,12 @@ std::string WebServer::update_json_(update::UpdateEntity *obj, JsonDetail start_
#endif
bool WebServer::canHandle(AsyncWebServerRequest *request) const {
#ifdef USE_ESP32
char url_buf[AsyncWebServerRequest::URL_BUF_SIZE];
StringRef url = request->url_to(url_buf);
#else
const auto &url = request->url();
#endif
const auto method = request->method();
// Static URL checks - use ESPHOME_F to keep strings in flash on ESP8266
@@ -2323,30 +2328,35 @@ bool WebServer::canHandle(AsyncWebServerRequest *request) const {
return false;
}
void WebServer::handleRequest(AsyncWebServerRequest *request) {
#ifdef USE_ESP32
char url_buf[AsyncWebServerRequest::URL_BUF_SIZE];
StringRef url = request->url_to(url_buf);
#else
const auto &url = request->url();
#endif
// Handle static routes first
if (url == "/") {
if (url == ESPHOME_F("/")) {
this->handle_index_request(request);
return;
}
#if !defined(USE_ESP32) && defined(USE_ARDUINO)
if (url == "/events") {
if (url == ESPHOME_F("/events")) {
this->events_.add_new_client(this, request);
return;
}
#endif
#ifdef USE_WEBSERVER_CSS_INCLUDE
if (url == "/0.css") {
if (url == ESPHOME_F("/0.css")) {
this->handle_css_request(request);
return;
}
#endif
#ifdef USE_WEBSERVER_JS_INCLUDE
if (url == "/0.js") {
if (url == ESPHOME_F("/0.js")) {
this->handle_js_request(request);
return;
}