aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/http
diff options
context:
space:
mode:
authorYasuhiro Matsumoto <mattn.jp@gmail.com>2011-07-13 14:39:33 -0700
committerRuss Cox <rsc@golang.org>2011-07-13 14:39:33 -0700
commit2012290c7e1872a1bf3faa848898761cb6958b61 (patch)
tree2e0787c52cf804c3f088c432a07f4e9db5f40747 /src/pkg/http
parent350504559e12272824d31e4d942d66929ba027c5 (diff)
downloadgo-2012290c7e1872a1bf3faa848898761cb6958b61.tar.xz
http: fix Content-Type of file extension.
ServeFile() pass empty string to serveFile(). serveFile() should get file extension via joining root and filename. R=bradfitz, rsc CC=golang-dev https://golang.org/cl/4654089
Diffstat (limited to 'src/pkg/http')
-rw-r--r--src/pkg/http/fs.go3
-rw-r--r--src/pkg/http/fs_test.go15
-rw-r--r--src/pkg/http/testdata/style.css1
3 files changed, 18 insertions, 1 deletions
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 {}