Commit 922ceadd authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

http: permit handlers to explicitly remove the Date header

We'll do the right thing by default, but people wanting minimal
response sizes can explicitly remove the Date header.
(empty fields aren't written out)

R=rsc
CC=golang-dev
https://golang.org/cl/4634048
parent cf201ed6
......@@ -781,6 +781,21 @@ func TestHandlerPanic(t *testing.T) {
}
}
func TestNoDate(t *testing.T) {
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
w.Header()["Date"] = nil
}))
defer ts.Close()
res, err := Get(ts.URL)
if err != nil {
t.Fatal(err)
}
_, present := res.Header["Date"]
if present {
t.Fatalf("Expected no Date header; got %v", res.Header["Date"])
}
}
type errorListener struct {
errs []os.Error
}
......
......@@ -254,7 +254,7 @@ func (w *response) WriteHeader(code int) {
}
}
if w.header.Get("Date") == "" {
if _, ok := w.header["Date"]; !ok {
w.Header().Set("Date", time.UTC().Format(TimeFormat))
}
......
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