From 8cd23c32651c25452eb1ac5a6b21f86c1ebffa51 Mon Sep 17 00:00:00 2001 From: Chris Sutcliff Date: Mon, 19 Oct 2026 21:05:33 +0100 Subject: [PATCH] fix(upload): send the 406 response for a rejected upload --- CHANGELOG_LATEST.md | 1 + src/ESP32React/UploadFileService.cpp | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 6d1651fb0..2a4890606 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -59,6 +59,7 @@ This release is based on the latest Espressif/Arduino core version 3. It brings - Guru Meditation (cache error) on HybridCompile builds when the EMS or console UART ISR ran from flash during a SPI flash read (WiFi power-down, mDNS, NVS). The UART ISR and ringbuf ISR helpers are now in IRAM - compile errors against Arduino 3.3.12 from Tasmota/Arduino headers named `console.h`, `network.h` and `httpClient.h`. Those EMS-ESP headers are now `emsesp_console.h`, `emsesp_network.h` and `emsesp_http_client.h` - HTTP OTA from WSL/mDNS stalled on IPv6 and used tiny write chunks. Uploads now resolve IPv4 and stream in 64 KB blocks (`scripts/upload.py`, `scripts/upload_cli.py`) +- a rejected upload (an invalid MD5 file, an unsupported file type) got no HTTP response: the connection was closed before the 406 was written, so `curl` reported "Empty reply from server". The 406 is now sent once the upload has been received ## Changed diff --git a/src/ESP32React/UploadFileService.cpp b/src/ESP32React/UploadFileService.cpp index a13a144a5..00f87adaf 100644 --- a/src/ESP32React/UploadFileService.cpp +++ b/src/ESP32React/UploadFileService.cpp @@ -247,16 +247,8 @@ void UploadFileService::handleError(AsyncWebServerRequest * request, int code) { emsesp::EMSESP::system_.uart_init(); // re-enable UART _ota.abort(); - // 406: the client sent a file we won't accept. Close now so the browser fails fast. - // Other codes wait for uploadComplete() to send, so we don't destroy the request mid-stream. - if (code == 406) { - request->send(request->beginResponse(code)); - _response_sent = true; - request->client()->close(); - _is_firmware = false; - _is_filesystem = false; - _is_recovery = false; - } + // uploadComplete() sends the error code. The web server only writes a response once the whole body has + // arrived, so closing the connection here to fail fast would lose the response. // if we aborted a filesystem upload, remount LittleFS so the device keeps working if (_is_filesystem) {