Skip to content
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

Don't crash when .mime file not exist in cache #1291

Merged
merged 2 commits into from
Dec 7, 2018

Conversation

kevinkassimo
Copy link
Contributor

This unblocks #1289 .
See #1289 (comment)
Tested locally, benchmark is working with this fix in place.

@kitsonk
Copy link
Contributor

kitsonk commented Dec 7, 2018

Not crashing is good, but it would be better to surface up the error instead of swallowing it, and to just check in the .mime into the cache, IMO. If the .mime doesn't exist, there is a problem, and we should fail, it means someone could be trying to exploit something. We need to be able to "trust" the media type retrieved from the cache.

@kevinkassimo
Copy link
Contributor Author

kevinkassimo commented Dec 7, 2018

@kitsonk we can still infer the file type with extension though and we can either generate a new .mime file based on the extension or warn the user. But yeah missing .mime is indeed an issue (and might have some security implications?). Let's see @ry 's opinion on this...

Honestly I don't really have some clear opinion/idea about this. But carrying around .mime files directly in the same folder as cached files also seems... inconvenient? It somehow sounds like a primordial package.json for every single file (if we ever want to even add more file metadata to it in the future?)...

@kitsonk
Copy link
Contributor

kitsonk commented Dec 7, 2018

Honestly I don't really have some clear opinion/idea about this. But carrying around .mime files directly in the same folder as cached files also seems... inconvenient? It somehow sounds like a package.json for every single file...

We want to respect the media type offered up the original server request. We cache locally each source file and use the file system to "index" each source file. The source file and the media type could be combined and cached together, but that actually adds more overhead with little value to re-parse it back out. So if we write out every individual source file, we write out every individual .mime.

// Option<String> -> Option<&str>
let maybe_content_type_str =
maybe_content_type_string.as_ref().map(String::as_str);
(source, map_content_type(&p, maybe_content_type_str))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to get a test below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - it’s nice to see these niche cases ironed out :)

@ry ry merged commit 0d3584c into denoland:master Dec 7, 2018
@ry ry mentioned this pull request Dec 7, 2018
ry added a commit to ry/deno that referenced this pull request Dec 7, 2018
- Don't crash when .mime file not exist in cache (denoland#1291)
- Process source maps in Rust instead of JS (denoland#1280)
- Use alternate TextEncoder/TextDecoder implementation (denoland#1281)
- Upgrade flatbuffers to 80d148
- Fix memory leaks (denoland#1265, denoland#1275)
@ry ry mentioned this pull request Dec 7, 2018
ry added a commit that referenced this pull request Dec 7, 2018
- Don't crash when .mime file not exist in cache (#1291)
- Process source maps in Rust instead of JS (#1280)
- Use alternate TextEncoder/TextDecoder implementation (#1281)
- Upgrade flatbuffers to 80d148
- Fix memory leaks (#1265, #1275)
@kevinkassimo kevinkassimo deleted the deno_dir/optional_mime branch December 27, 2019 07:51
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.

None yet

3 participants