Commit 49741f23 authored by Clement Skau's avatar Clement Skau Committed by Russ Cox

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
parent 43582bad
......@@ -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")
......
......@@ -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 = ""
}
......
......@@ -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
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment