src/pkg/http/fs.go | 4 +++- src/pkg/http/fs_test.go | 17 ++++++++++++++++- diff --git a/src/pkg/http/fs.go b/src/pkg/http/fs.go index 17d5297b82c86614d849a7d9ef33b3a8b13b2c4e..28a0c51ef5b9c6d1fcd6bda042c7188df9e7d557 100644 --- a/src/pkg/http/fs.go +++ b/src/pkg/http/fs.go @@ -175,7 +175,9 @@ w.Header().Set("Content-Range", fmt.Sprintf("bytes %d-%d/%d", ra.start, ra.start+ra.length-1, d.Size)) } w.Header().Set("Accept-Ranges", "bytes") - w.Header().Set("Content-Length", strconv.Itoa64(size)) + if w.Header().Get("Content-Encoding") == "" { + w.Header().Set("Content-Length", strconv.Itoa64(size)) + } w.WriteHeader(code) diff --git a/src/pkg/http/fs_test.go b/src/pkg/http/fs_test.go index b94196258ee8dc1f204124abfa0a42365175ded9..554053449ecbd57cb9788f438a3c4984b6729a73 100644 --- a/src/pkg/http/fs_test.go +++ b/src/pkg/http/fs_test.go @@ -101,12 +101,27 @@ if err != nil { t.Fatal(err) } if h := resp.Header.Get("Content-Type"); h != want { - t.Errorf("Content-Type mismatch: got %q, want %q", h, want) + t.Errorf("Content-Type mismatch: got %d, want %d", h, want) } } get("text/plain; charset=utf-8") override = true get(ctype) +} + +func TestServeFileWithContentEncoding(t *testing.T) { + ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { + w.Header().Set("Content-Encoding", "foo") + ServeFile(w, r, "testdata/file") + })) + defer ts.Close() + resp, err := Get(ts.URL) + if err != nil { + t.Fatal(err) + } + if g, e := resp.ContentLength, int64(-1); g != e { + t.Errorf("Content-Length mismatch: got %q, want %q", g, e) + } } func getBody(t *testing.T, req Request) (*Response, []byte) {