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

Add application/x-typescript mime type support #1111

Merged
merged 1 commit into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/deno_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,8 @@ fn map_content_type(path: &Path, content_type: Option<&str>) -> msg::MediaType {
"application/typescript"
| "text/typescript"
| "video/vnd.dlna.mpeg-tts"
| "video/mp2t" => msg::MediaType::TypeScript,
| "video/mp2t"

Choose a reason for hiding this comment

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

"video/vnd.dlna.mpeg-tts" and "video/mp2t" are mine type for video file not typescript

Copy link
Contributor

Choose a reason for hiding this comment

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

They are common types that are assigned by web servers to .ts files incorrectly. It is intentional.

| "application/x-typescript" => msg::MediaType::TypeScript,
"application/javascript"
| "text/javascript"
| "application/ecmascript"
Expand Down Expand Up @@ -857,6 +858,10 @@ fn test_map_content_type() {
map_content_type(Path::new("foo/bar"), Some("video/mp2t")),
msg::MediaType::TypeScript
);
assert_eq!(
map_content_type(Path::new("foo/bar"), Some("application/x-typescript")),
msg::MediaType::TypeScript
);
assert_eq!(
map_content_type(Path::new("foo/bar"), Some("application/javascript")),
msg::MediaType::JavaScript
Expand Down
2 changes: 2 additions & 0 deletions tests/019_media_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { loaded as loadedTs1 } from "http://localhost:4545/tests/subdir/mt_text_typescript.t1.ts";
import { loaded as loadedTs2 } from "http://localhost:4545/tests/subdir/mt_video_vdn.t2.ts";
import { loaded as loadedTs3 } from "http://localhost:4545/tests/subdir/mt_video_mp2t.t3.ts";
import { loaded as loadedTs4 } from "http://localhost:4545/tests/subdir/mt_application_x_typescript.t4.ts";
import { loaded as loadedJs1 } from "http://localhost:4545/tests/subdir/mt_text_javascript.j1.js";
import { loaded as loadedJs2 } from "http://localhost:4545/tests/subdir/mt_application_ecmascript.j2.js";
import { loaded as loadedJs3 } from "http://localhost:4545/tests/subdir/mt_text_ecmascript.j3.js";
Expand All @@ -16,6 +17,7 @@ console.log(
loadedTs1,
loadedTs2,
loadedTs3,
loadedTs4,
loadedJs1,
loadedJs2,
loadedJs3,
Expand Down
3 changes: 2 additions & 1 deletion tests/019_media_types.ts.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Downloading http://localhost:4545/tests/subdir/mt_text_typescript.t1.ts
Downloading http://localhost:4545/tests/subdir/mt_video_vdn.t2.ts
Downloading http://localhost:4545/tests/subdir/mt_video_mp2t.t3.ts
Downloading http://localhost:4545/tests/subdir/mt_application_x_typescript.t4.ts
Downloading http://localhost:4545/tests/subdir/mt_text_javascript.j1.js
Downloading http://localhost:4545/tests/subdir/mt_application_ecmascript.j2.js
Downloading http://localhost:4545/tests/subdir/mt_text_ecmascript.j3.js
Downloading http://localhost:4545/tests/subdir/mt_application_x_javascript.j4.js
success true true true true true true true
success true true true true true true true true
1 change: 1 addition & 0 deletions tests/subdir/mt_application_x_typescript.t4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const loaded = true;
2 changes: 2 additions & 0 deletions tools/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def guess_type(self, path):
return "video/vnd.dlna.mpeg-tts"
if ".t3." in path:
return "video/mp2t"
if ".t4." in path:
return "application/x-typescript"
if ".j1." in path:
return "text/javascript"
if ".j2." in path:
Expand Down