[web_server] Remove dead ESP-IDF event source connect callback and pack expose_log_ (#20130)

This commit is contained in:
J. Nick Koston
2026-10-05 12:15:58 +13:00
committed by GitHub
parent 4f9cd7821a
commit feedea4954
3 changed files with 4 additions and 14 deletions
+3 -1
View File
@@ -531,6 +531,9 @@ class WebServer final : public Component, public AsyncWebHandler {
bool include_internal_{false};
protected:
// Declared here so it packs into the padding after include_internal_
bool expose_log_{true};
void add_sorting_info_(JsonObject &root, EntityBase *entity);
#ifdef USE_LIGHT
@@ -614,7 +617,6 @@ class WebServer final : public Component, public AsyncWebHandler {
#ifdef USE_WEBSERVER_JS_INCLUDE
const char *js_include_{nullptr};
#endif
bool expose_log_{true};
#ifdef USE_WEBSERVER_ALLOWED_ORIGINS
// Extra origins allowed to make cross-origin browser requests ("*" means any origin).
// Only compiled when allowed_origins is configured; same-origin is always allowed regardless.
@@ -761,7 +761,7 @@ void AsyncEventSource::adopt_pending_sessions_main_loop_() {
this->has_pending_sessions_.store(false, std::memory_order_relaxed);
}
for (auto *rsp : incoming) {
// Already disconnected? Drop it; skip on_connect_/session start on a dead session.
// Already disconnected? Drop it; skip session start on a dead session.
if (rsp->safe_to_delete_()) {
delete rsp; // NOLINT(cppcoreguidelines-owning-memory)
continue;
@@ -775,12 +775,7 @@ void AsyncEventSource::adopt_pending_sessions_main_loop_() {
continue;
}
this->sessions_.push_back(rsp);
// Prime first so on_connect_ observes a session that has already sent its
// initial ping/config/sorting_groups, matching the pre-refactor ordering.
rsp->start_session_main_loop_();
if (this->on_connect_) {
this->on_connect_(rsp);
}
}
}
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
@@ -379,7 +379,6 @@ using AsyncEventSourceClient = AsyncEventSourceResponse;
class AsyncEventSource : public AsyncWebHandler {
friend class AsyncEventSourceResponse;
using connect_handler_t = std::function<void(AsyncEventSourceClient *)>;
public:
AsyncEventSource(StringRef url, esphome::web_server::WebServer *ws) : url_(url), web_server_(ws) {}
@@ -394,11 +393,6 @@ class AsyncEventSource : public AsyncWebHandler {
}
// NOLINTNEXTLINE(readability-identifier-naming)
void handleRequest(AsyncWebServerRequest *request) override;
// Callback runs on the main loop (not the httpd task) after the session's
// initial ping/config/sorting_groups have been sent.
// NOLINTNEXTLINE(readability-identifier-naming)
void onConnect(connect_handler_t &&cb) { this->on_connect_ = std::move(cb); }
void try_send_nodefer(const char *message, size_t message_len, const char *event = nullptr, uint32_t id = 0,
uint32_t reconnect = 0);
void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator);
@@ -418,7 +412,6 @@ class AsyncEventSource : public AsyncWebHandler {
// Httpd-task intake; guarded by pending_mutex_, gated by has_pending_sessions_.
std::vector<AsyncEventSourceResponse *> pending_sessions_;
Mutex pending_mutex_;
connect_handler_t on_connect_{};
esphome::web_server::WebServer *web_server_;
std::atomic<bool> has_pending_sessions_{false};
};