Permalink
Browse files

Fix Content-Type bug in FS

Fixes #417
  • Loading branch information...
erikdubbelboer committed Sep 20, 2018
1 parent da9ba61 commit d53df6794551ddc6c85cfec94d9a304c95266e6d
Showing with 25 additions and 1 deletion.
  1. +2 −1 fs.go
  2. +22 −0 fs_test.go
  3. +1 −0 testdata/test.png
View
3 fs.go
@@ -823,7 +823,8 @@ func (h *fsHandler) handleRequest(ctx *RequestCtx) {
}
}
}
if len(ctx.Response.Header.ContentType()) == 0 {
hdr.noDefaultContentType = true
if len(hdr.ContentType()) == 0 {
ctx.SetContentType(ff.contentType)
}
ctx.SetStatusCode(statusCode)
View
@@ -682,3 +682,25 @@ func testFileExtension(t *testing.T, path string, compressed bool, compressedFil
t.Fatalf("unexpected file extension for file %q: %q. Expecting %q", path, ext, expectedExt)
}
}
func TestServeFileContentType(t *testing.T) {
var ctx RequestCtx
var req Request
req.Header.SetMethod("GET")
req.SetRequestURI("http://foobar.com/baz")
ctx.Init(&req, nil, nil)
ServeFile(&ctx, "testdata/test.png")
var resp Response
s := ctx.Response.String()
br := bufio.NewReader(bytes.NewBufferString(s))
if err := resp.Read(br); err != nil {
t.Fatalf("unexpected error: %s", err)
}
expected := []byte("image/png")
if !bytes.Equal(resp.Header.ContentType(), expected) {
t.Fatalf("Unexpected Content-Type, expected: %q got %q", expected, resp.Header.ContentType())
}
}
View
@@ -0,0 +1 @@

0 comments on commit d53df67

Please sign in to comment.