This commit is contained in:
J. Nick Koston
2025-11-17 21:57:21 -06:00
parent 7f4205b82c
commit 11c8865248
2 changed files with 2 additions and 7 deletions
@@ -52,13 +52,7 @@ void CaptivePortal::handle_wifisave(AsyncWebServerRequest *request) {
ESP_LOGI(TAG, " Password=" LOG_SECRET("'%s'"), psk.c_str());
wifi::global_wifi_component->save_wifi_sta(ssid, psk);
wifi::global_wifi_component->start_scanning();
// Add Connection: close header to ensure socket is released immediately
// Without this, sockets can stay in TIME_WAIT and exhaust the socket pool
auto *response = request->beginResponse(302, ESPHOME_F("text/plain"), ESPHOME_F(""));
response->addHeader(ESPHOME_F("Location"), ESPHOME_F("/?save"));
response->addHeader(ESPHOME_F("Connection"), ESPHOME_F("close"));
request->send(response);
request->redirect(ESPHOME_F("/?save"));
}
void CaptivePortal::setup() {
@@ -242,6 +242,7 @@ void AsyncWebServerRequest::send(int code, const char *content_type, const char
void AsyncWebServerRequest::redirect(const std::string &url) {
httpd_resp_set_status(*this, "302 Found");
httpd_resp_set_hdr(*this, "Location", url.c_str());
httpd_resp_set_hdr(*this, "Connection", "close");
httpd_resp_send(*this, nullptr, 0);
}