1
0
mirror of https://github.com/golang/go synced 2024-11-22 04:04:40 -07:00

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
This commit is contained in:
Hong Ruiqi 2012-02-12 23:45:19 -05:00 committed by Russ Cox
parent 3760213e6e
commit c58b6ad022

View 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
}