-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Media Type enforcement #1020
Media Type enforcement #1020
Conversation
src/deno_dir.rs
Outdated
@@ -104,26 +105,59 @@ impl DenoDir { | |||
} | |||
} | |||
|
|||
// convert a ContentType string into a enumerated MediaType | |||
fn map_content_type(self: &DenoDir, path: &Path, content_type: Option<&str>) -> msg::MediaType { |
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.
It doesn't seem like this needs to be a method, since it doesn't use self
. Break this out into a standalone function. Add a test for it in this file.
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.
Ok, I will, I just was struggling with how to invoke it. I will figure that out... I guess it needs to go outside of the impl
. It is obvious now that I say it.
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.
Awesome - I'm glad you're working on this!
Regarding testing I think tools/http_server.py should be modified to have a handler that returns different content-type headers.
Looks like a good start - ping me when I should review again.
@ry do you have an opinion on how we should resolve unknown media types? Specifically, gist returns things as A couple solutions I can think of:
Browsers tend to be really really strict about it, so it feels like we should be too. It does mean that we can't host |
@kitsonk Looking at the extension should solve it for gists ? I think we should use the extension. Otherwise I have no opinion. |
9800db8
to
16b3e62
Compare
@ry ok, I think this is now complete and ready for review. So for the "gist" issue, if the media type is The media type that is received for remote modules is cached along side the source code with a |
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.
Looks good! Works for me locally
@@ -27,7 +28,7 @@ pub fn get_client() -> Client<Connector, hyper::Body> { | |||
|
|||
// The CodeFetch message is used to load HTTP javascript resources and expects a | |||
// synchronous response, this utility method supports that. | |||
pub fn fetch_sync_string(module_name: &str) -> DenoResult<String> { | |||
pub fn fetch_sync_string(module_name: &str) -> DenoResult<(String, String)> { |
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.
How about returning DenoResult<(String, msg::MediaType)>
?
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 took a look at this and I decided not to change it... within http_util
it doesn't really have a concept of the enum yet, as that is decided in deno_dir.rs
. So a decision here, might not be right when combined with other logic contained in deno_dir.rs
, so I would like to leave it as (String, String)
.
Let's try to land this before #1039 |
Hmmm... the appveyor |
@kitsonk Hmm - strange - make sure you're rebased on master and using the rustfmt in third_party. |
@ry I was/am and I was using |
@ry 😖 😕
|
Well, and #1065 which currently includes the commit here passed CI on appveyor. Seems to be some sort of odd issue while GitHub was 💥. I suspect restarting the CI would cause the issue to disappear (as well as complete the Travis CI as well). |
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.
LGTM - very nice! it seems like the import system is actually functioning quite well now !
- Add URLSearchParams (denoland#1049) - Implement clone for FetchResponse (denoland#1054) - Use content-type headers when importing from URLs. (denoland#1020) - Use checkJs option, JavaScript will be type checked and users can supply JSDoc type annotations that will be enforced by Deno (denoland#1068) - Add separate http/https cache dirs to DENO_DIR (denoland#971) - Support https in fetch. (denoland#1100) - Add chmod/chmodSync on unix (denoland#1088) - Remove broken features: --deps and trace() (denoland#1103) - Ergonomics: Prompt TTY for permission escalation (denoland#1081)
- Add URLSearchParams (#1049) - Implement clone for FetchResponse (#1054) - Use content-type headers when importing from URLs. (#1020) - Use checkJs option, JavaScript will be type checked and users can supply JSDoc type annotations that will be enforced by Deno (#1068) - Add separate http/https cache dirs to DENO_DIR (#971) - Support https in fetch. (#1100) - Add chmod/chmodSync on unix (#1088) - Remove broken features: --deps and trace() (#1103) - Ergonomics: Prompt TTY for permission escalation (#1081)
Fixes #702
This PR is a WIP for media type enforcement.
When remote modules are retrieved, the privileged resolves the media type of the file. First it respects the
Content-Type
header if present. If no header present, it will utilise the extension. For local modules the privileged side always uses the extension to determine the media type.The Deno compiler then respects that media type when providing file type information to TypeScript.
Things not done yet:
text/plain
for files. At the moment, that assigns it aMediaType.Unknown
which the compiler assumes is then JavaScript. What to do with media types that are not "valid" needs to be figured out.