forked from me-no-dev/ESPAsyncWebServer
-
Notifications
You must be signed in to change notification settings - Fork 70
feature: refactor content type and MIME list #241
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
Merged
mathieucarbou
merged 6 commits into
ESP32Async:main
from
JosePineiro:feature/mime-type-refactor
Aug 5, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eab1ad7
feature: refactor content type and MIME list
JosePineiro ec51342
Update src/WebResponses.cpp
JosePineiro 7103517
Add files via upload
JosePineiro 2ec3bbe
Add files via upload
JosePineiro b0db1e1
ci(pre-commit): Apply automatic fixes
pre-commit-ci-lite[bot] 34e97e1
Merge branch 'main' into feature/mime-type-refactor
mathieucarbou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
application,text,image, etc. To speed up the comparison, first test if the content type starts withapplication/, text/,image/, etc. Then, for each one, you only test the second part of the content type. This will divide the number of comparisons to do way more and also avoid redoing each time the same comparisons for the categories.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.
Extension removed:
Having unnecessary extensions slows down your code, increases its size, and makes it harder to maintain. It's not a free breakfast.
Do you still think it's worth keeping them?
I'll restore the old definition of for JS
I realize it's not the most efficient way to speed things up. But the cost is very low (I simply change the order) and the benefit is good. Do you think it's reasonable to leave it like this for now?
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.
Reordering the conditions is not something I would do because it just adds noise and more difficulties to review the diff.
I would do no reordering and instead to the correct code change to optimize the comparison by checking the mime category first and the the second part.
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.
For content types: they should NEVER be linked to a file extension.
content types should be set by the user, depending on HOW the resource is used.
That’s totally ok to answer some js content with text/plain, like it is totally fine to serve an image with application/octet-stream. These are different usages on consumer side.
That being said, the server can assume some default content types for common static resources served on web pages like html, images, css, js, etc for example in the case of serveStatic because it assumes a standard use in a web browser.
And yes, defaulting to text/plain for some is bad, especially for binary content. Default should be application/octet-stream I think.