Skip to content

fix(upload): send the 406 response for a rejected upload - #3306

Merged
proddy merged 1 commit into
emsesp:devfrom
csutcliff:pr/upload-406-response
Oct 19, 2026
Merged

proddy merged 1 commit into
emsesp:devfrom
csutcliff:pr/upload-406-response

Conversation

@csutcliff

Copy link
Copy Markdown
Contributor

Problem

When an upload is rejected with 406 (an invalid MD5 file, an unsupported file type), UploadFileService::handleError() calls request->send() and then closes the connection straight away so the client fails fast. ESPAsyncWebServer's send() only stores the response. It is written once the whole request body has been parsed, so the close always wins and the client gets no response at all. curl reports "Empty reply from server" (exit 52) instead of the 406.

Fix

Don't send or close in handleError() for 406. uploadComplete() already sends the stored error code once the body has arrived, as it does for every other code. The later chunks are already ignored once an error is recorded.

The cost is that a rejected large file is uploaded in full before the 406 arrives, the same as a firmware for the wrong chip (503) already behaves. The WebUI only offers .json, .bin and .md5, and shows the same message for any failed upload.

Testing

BBQKees Gateway E32 V2 (s_16M_P, with #3305 applied so the rejected uploads don't crash), curl to /rest/uploadFile:

Upload Before After
empty EMS-ESP.md5 Empty reply from server 406 in 0.17 s
EMS-ESP.md5 containing hello Empty reply from server 406
notes.txt Empty reply from server 406
1 MB big.zip 406 after the upload, 5.3 s
valid .md5 then .bin ok ok
  • Builds for s_16M_P, clang-format clean.

The Recovery firmware's uploadFail() (recovery/main.cpp) closes the connection the same way after a 406. Not changed here.

Checklist

  • Against the dev branch
  • Formatted per .clang-format
  • New logic is commented
  • One fix only, only relevant files touched
  • CHANGELOG_LATEST.md updated
  • I accept the CLA in CONTRIBUTING.md

@proddy
proddy merged commit f20c064 into emsesp:dev Oct 19, 2026
@proddy proddy added this to the 3.9.0 milestone Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants