mirror of
https://github.com/golang/go
synced 2024-11-21 20:04:44 -07:00
http: handle status 304 correctly
- cannot send body - should not send body-related headers R=r CC=golang-dev https://golang.org/cl/1499041
This commit is contained in:
parent
962e8b8736
commit
24baca4936
@ -26,6 +26,7 @@ import (
|
||||
// Errors introduced by the HTTP server.
|
||||
var (
|
||||
ErrWriteAfterFlush = os.NewError("Conn.Write called after Flush")
|
||||
ErrBodyNotAllowed = os.NewError("http: response status code does not allow body")
|
||||
ErrHijacked = os.NewError("Conn has been hijacked")
|
||||
)
|
||||
|
||||
@ -138,6 +139,11 @@ func (c *Conn) WriteHeader(code int) {
|
||||
}
|
||||
c.wroteHeader = true
|
||||
c.status = code
|
||||
if code == StatusNotModified {
|
||||
// Must not have body.
|
||||
c.header["Content-Type"] = "", false
|
||||
c.header["Transfer-Encoding"] = "", false
|
||||
}
|
||||
c.written = 0
|
||||
if !c.Req.ProtoAtLeast(1, 0) {
|
||||
return
|
||||
@ -173,6 +179,11 @@ func (c *Conn) Write(data []byte) (n int, err os.Error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if c.status == StatusNotModified {
|
||||
// Must not have body.
|
||||
return 0, ErrBodyNotAllowed
|
||||
}
|
||||
|
||||
c.written += int64(len(data)) // ignoring errors, for errorKludge
|
||||
|
||||
// TODO(rsc): if chunking happened after the buffering,
|
||||
|
Loading…
Reference in New Issue
Block a user