mirror of
https://github.com/golang/go
synced 2024-11-12 08:20:22 -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:
parent
43582bad33
commit
49741f23d5
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user