diff --git a/src/pkg/http/fs.go b/src/pkg/http/fs.go index 0b830053a9..34fe77d6bd 100644 --- a/src/pkg/http/fs.go +++ b/src/pkg/http/fs.go @@ -222,7 +222,8 @@ func serveFile(w ResponseWriter, r *Request, fs FileSystem, name string, redirec // ServeFile replies to the request with the contents of the named file or directory. func ServeFile(w ResponseWriter, r *Request, name string) { - serveFile(w, r, Dir(name), "", false) + dir, file := filepath.Split(name) + serveFile(w, r, Dir(dir), file, false) } type fileHandler struct { diff --git a/src/pkg/http/fs_test.go b/src/pkg/http/fs_test.go index dbbdf05bdc..0c6edba9bc 100644 --- a/src/pkg/http/fs_test.go +++ b/src/pkg/http/fs_test.go @@ -175,6 +175,21 @@ func TestServeFileContentType(t *testing.T) { get(ctype) } +func TestServeFileMimeType(t *testing.T) { + ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { + ServeFile(w, r, "testdata/style.css") + })) + defer ts.Close() + resp, err := Get(ts.URL) + if err != nil { + t.Fatal(err) + } + want := "text/css" + if h := resp.Header.Get("Content-Type"); h != want { + t.Errorf("Content-Type mismatch: got %q, want %q", h, want) + } +} + func TestServeFileWithContentEncoding(t *testing.T) { ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { w.Header().Set("Content-Encoding", "foo") diff --git a/src/pkg/http/testdata/style.css b/src/pkg/http/testdata/style.css new file mode 100644 index 0000000000..208d16d421 --- /dev/null +++ b/src/pkg/http/testdata/style.css @@ -0,0 +1 @@ +body {}