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

Attach correct Content-Type to HTTP header #4555

Merged
merged 6 commits into from
Apr 1, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
x
  • Loading branch information
ry committed Apr 1, 2020
commit 32580cac88bef473b2042d828d9ce5ce11fb189b
8 changes: 4 additions & 4 deletions std/http/file_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

const { args, stat, readdir, open, exit } = Deno;
import { contentType } from "../media_types/mod.ts";
import { posix, basename } from "../path/mod.ts";
import { posix, extname } from "../path/mod.ts";
import { listenAndServe, ServerRequest, Response } from "./server.ts";
import { parse } from "../flags/mod.ts";
import { assert } from "../testing/asserts.ts";
Expand Down Expand Up @@ -104,7 +104,7 @@ export async function serveFile(
const [file, fileInfo] = await Promise.all([open(filePath), stat(filePath)]);
const headers = new Headers();
headers.set("content-length", fileInfo.size.toString());
const contentTypeValue = contentType(basename(filePath));
const contentTypeValue = contentType(extname(filePath));
if (contentTypeValue) {
headers.set("content-type", contentTypeValue);
}
Expand Down Expand Up @@ -298,7 +298,7 @@ function html(strings: TemplateStringsArray, ...values: unknown[]): string {
return html;
}

async function main(): Promise<void> {
function main(): Promise<void> {
listenAndServe(
addr,
async (req): Promise<void> => {
Expand Down Expand Up @@ -338,5 +338,5 @@ async function main(): Promise<void> {
}

if (import.meta.main) {
await main();
main();
}