1
0
mirror of https://github.com/golang/go synced 2024-11-24 12:00:14 -07:00

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
This commit is contained in:
Clement Skau 2011-01-19 10:05:48 -05:00 committed by Russ Cox
parent 43582bad33
commit 49741f23d5
3 changed files with 6 additions and 2 deletions

View File

@ -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")

View File

@ -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 = ""
}

View File

@ -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
}