mirror of
https://github.com/golang/go
synced 2024-09-28 20:14:28 -06:00
net/http: always set Content-Length in serveContent
This commit is contained in:
parent
4cd201b14b
commit
3aff9126f5
@ -343,9 +343,7 @@ func serveContent(w ResponseWriter, r *Request, name string, modtime time.Time,
|
||||
}
|
||||
|
||||
w.Header().Set("Accept-Ranges", "bytes")
|
||||
if w.Header().Get("Content-Encoding") == "" {
|
||||
w.Header().Set("Content-Length", strconv.FormatInt(sendSize, 10))
|
||||
}
|
||||
w.Header().Set("Content-Length", strconv.FormatInt(sendSize, 10))
|
||||
|
||||
w.WriteHeader(code)
|
||||
|
||||
|
@ -571,7 +571,7 @@ func testServeDirWithoutTrailingSlash(t *testing.T, mode testMode) {
|
||||
}
|
||||
}
|
||||
|
||||
// Tests that ServeFile doesn't add a Content-Length if a Content-Encoding is
|
||||
// Tests that ServeFile adds a Content-Length even if a Content-Encoding is
|
||||
// specified.
|
||||
func TestServeFileWithContentEncoding(t *testing.T) { run(t, testServeFileWithContentEncoding) }
|
||||
func testServeFileWithContentEncoding(t *testing.T, mode testMode) {
|
||||
@ -593,7 +593,7 @@ func testServeFileWithContentEncoding(t *testing.T, mode testMode) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
if g, e := resp.ContentLength, int64(-1); g != e {
|
||||
if g, e := resp.ContentLength, int64(11); g != e {
|
||||
t.Errorf("Content-Length mismatch: got %d, want %d", g, e)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user