From 49741f23d5938eff80f2c8ca4b16c9f1b0e15f7d Mon Sep 17 00:00:00 2001 From: Clement Skau Date: Wed, 19 Jan 2011 10:05:48 -0500 Subject: [PATCH] http: fix Content-Range and Content-Length in response RFC2616 sections 4.4 and 14.16: * Cannot use Content-Length with non-identity Transfer-Encoding * Content-Range response is "bytes x-y/z" not "x-y/z" R=rsc CC=golang-dev https://golang.org/cl/4018041 --- src/pkg/http/fs.go | 2 +- src/pkg/http/fs_test.go | 2 +- src/pkg/http/server.go | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pkg/http/fs.go b/src/pkg/http/fs.go index b3cae19a50..bbfa58d264 100644 --- a/src/pkg/http/fs.go +++ b/src/pkg/http/fs.go @@ -166,7 +166,7 @@ func serveFile(w ResponseWriter, r *Request, name string, redirect bool) { } size = ra.length code = StatusPartialContent - w.SetHeader("Content-Range", fmt.Sprintf("%d-%d/%d", ra.start, ra.start+ra.length, d.Size)) + w.SetHeader("Content-Range", fmt.Sprintf("bytes %d-%d/%d", ra.start, ra.start+ra.length-1, d.Size)) } w.SetHeader("Accept-Ranges", "bytes") diff --git a/src/pkg/http/fs_test.go b/src/pkg/http/fs_test.go index 0f71356926..0a5636b88d 100644 --- a/src/pkg/http/fs_test.go +++ b/src/pkg/http/fs_test.go @@ -134,7 +134,7 @@ func TestServeFile(t *testing.T) { if rt.code == StatusRequestedRangeNotSatisfiable { continue } - h := fmt.Sprintf("%d-%d/%d", rt.start, rt.end, testFileLength) + h := fmt.Sprintf("bytes %d-%d/%d", rt.start, rt.end-1, testFileLength) if rt.r == "" { h = "" } diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go index 2ecdd5ee25..644724f58e 100644 --- a/src/pkg/http/server.go +++ b/src/pkg/http/server.go @@ -229,6 +229,10 @@ func (w *response) WriteHeader(code int) { w.header["Transfer-Encoding"] = "", false w.chunking = false } + // Cannot use Content-Length with non-identity Transfer-Encoding. + if w.chunking { + w.header["Content-Length"] = "", false + } if !w.req.ProtoAtLeast(1, 0) { return }