-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[fix] Expand list of allowed mime types for binary bodies #1687
Merged
benmccann
merged 21 commits into
sveltejs:master
from
JeanJPNM:allow-any-binary-content
Jul 12, 2021
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f3d5fc9
allow binary bodies with any content type
JeanJPNM 2d30a88
add checks for common binary request bodies
JeanJPNM 3cd030d
add validation for allowed types
JeanJPNM 7c7a25c
Merge branch 'master' into allow-any-binary-content
JeanJPNM f82abc1
Merge branch 'master' into allow-any-binary-content
JeanJPNM 82ef186
add function to get the body type
JeanJPNM dc70750
expose utils file to adapters
JeanJPNM 3ec5fdd
replace repeated checks by the utils function
JeanJPNM 1ac70ca
fix import
JeanJPNM f6e2a24
rename function to `isContentTypeBinary`
JeanJPNM 41c60d8
return a boolean instead of a string enum
JeanJPNM 304e4d3
move function to `adapter-utils.js`
JeanJPNM 27ac1c5
update adapters
JeanJPNM 819ba95
fix issues
JeanJPNM 9e79f75
handle undefined content type
JeanJPNM 6562f17
add changeset
JeanJPNM 949bcb1
small style changes
JeanJPNM a8b4cbf
Update packages/kit/src/runtime/server/endpoint.js
benmccann 084d26b
Update packages/kit/src/core/adapter-utils.js
benmccann 01414fb
Update packages/kit/src/core/adapter-utils.js
benmccann e4fac6d
Update packages/kit/src/core/adapter-utils.js
benmccann 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@sveltejs/adapter-cloudflare-workers': patch | ||
'@sveltejs/adapter-netlify': patch | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
Update and consolidate checks for binary body types |
This file contains 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 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Decides how the body should be parsed based on its mime type. | ||
* | ||
* This is intended to be used with both requests and responses, to have a consistent body parsing across adapters. | ||
* | ||
* @param {string} content_type The `content-type` header of a request/response. | ||
* @returns {boolean} | ||
*/ | ||
export function isContentTypeBinary(content_type) { | ||
return ( | ||
content_type.startsWith('image/') || | ||
content_type.startsWith('audio/') || | ||
content_type.startsWith('video/') || | ||
content_type.startsWith('application/octet-stream') | ||
); | ||
} |
This file contains 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 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.
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 logic is possibly still too blunt. There are at least a few content types I'd consider common for which I think this would return the wrong result:
image/svg+xml
application/zip
application/pdf
An escape hatch for the developer here might be useful too given all the potential edge cases that the wonderful world of mime types involves.
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.
I know that's why I made #1829
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.
I sent #1890 to help with this