summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-06-03 16:09:37 -0700
committerRuss Cox <rsc@golang.org>2010-06-03 16:09:37 -0700
commitcc7ef817e786806aa0c074d3c275506310c8d013 (patch)
treebfe068c13656c7b0822c82ea72748004152faf44
parentbb15435e2d5f3a0cc105edef55d0520f16e4ed77 (diff)
downloadgolang-cc7ef817e786806aa0c074d3c275506310c8d013.tar.gz
http: handle status 304 correctly
- cannot send body - should not send body-related headers R=r CC=golang-dev http://codereview.appspot.com/1499041
-rw-r--r--src/pkg/http/server.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go
index a28eb25ee..9f0bc6608 100644
--- a/src/pkg/http/server.go
+++ b/src/pkg/http/server.go
@@ -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,