]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: use mtime < t+1s to check for unmodified
authorHong Ruiqi <hongruiqi@gmail.com>
Mon, 13 Feb 2012 04:45:19 +0000 (23:45 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 13 Feb 2012 04:45:19 +0000 (23:45 -0500)
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

index 0e192eb99c9b7fabd0f59d010f84c9de07a17b53..f35dd32c3055426cfed876f8af69ff8ea5454440 100644 (file)
@@ -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
        }