From c58b6ad02203cc0f4ba3cd0a38ce222d177cc75e Mon Sep 17 00:00:00 2001 From: Hong Ruiqi Date: Sun, 12 Feb 2012 23:45:19 -0500 Subject: [PATCH] net/http: use mtime < t+1s to check for unmodified The Date-Modified header truncates sub-second precision, so use mtime < t+1s instead of mtime <= t to check for unmodified. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5655052 --- src/pkg/net/http/fs.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pkg/net/http/fs.go b/src/pkg/net/http/fs.go index 0e192eb99c9..f35dd32c305 100644 --- a/src/pkg/net/http/fs.go +++ b/src/pkg/net/http/fs.go @@ -186,7 +186,10 @@ func checkLastModified(w ResponseWriter, r *Request, modtime time.Time) bool { if modtime.IsZero() { return false } - if t, err := time.Parse(TimeFormat, r.Header.Get("If-Modified-Since")); err == nil && modtime.After(t) { + + // The Date-Modified header truncates sub-second precision, so + // use mtime < t+1s instead of mtime <= t to check for unmodified. + if t, err := time.Parse(TimeFormat, r.Header.Get("If-Modified-Since")); err == nil && modtime.Before(t.Add(1*time.Second)) { w.WriteHeader(StatusNotModified) return true }