diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-01-02 15:05:27 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-01-21 23:53:22 -0800 |
commit | 5a8ea165926cb0737ab03bc48c18dc5198ab5305 (patch) | |
tree | 962dc3357c57f019f85658f99e2e753e30201c27 /libgo/go/net/http/fs.go | |
parent | 6ac6529e155c9baa0aaaed7aca06bd38ebda5b43 (diff) | |
download | gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.tar.gz |
libgo: update to Go1.14beta1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/214297
Diffstat (limited to 'libgo/go/net/http/fs.go')
-rw-r--r-- | libgo/go/net/http/fs.go | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/libgo/go/net/http/fs.go b/libgo/go/net/http/fs.go index 41d46dced2a..d2144857e84 100644 --- a/libgo/go/net/http/fs.go +++ b/libgo/go/net/http/fs.go @@ -384,15 +384,18 @@ func checkIfUnmodifiedSince(r *Request, modtime time.Time) condResult { if ius == "" || isZeroTime(modtime) { return condNone } - if t, err := ParseTime(ius); err == nil { - // The Date-Modified header truncates sub-second precision, so - // use mtime < t+1s instead of mtime <= t to check for unmodified. - if modtime.Before(t.Add(1 * time.Second)) { - return condTrue - } - return condFalse + t, err := ParseTime(ius) + if err != nil { + return condNone } - return condNone + + // The Last-Modified header truncates sub-second precision so + // the modtime needs to be truncated too. + modtime = modtime.Truncate(time.Second) + if modtime.Before(t) || modtime.Equal(t) { + return condTrue + } + return condFalse } func checkIfNoneMatch(w ResponseWriter, r *Request) condResult { @@ -436,9 +439,10 @@ func checkIfModifiedSince(r *Request, modtime time.Time) condResult { if err != nil { return condNone } - // The Date-Modified header truncates sub-second precision, so - // use mtime < t+1s instead of mtime <= t to check for unmodified. - if modtime.Before(t.Add(1 * time.Second)) { + // The Last-Modified header truncates sub-second precision so + // the modtime needs to be truncated too. + modtime = modtime.Truncate(time.Second) + if modtime.Before(t) || modtime.Equal(t) { return condFalse } return condTrue @@ -582,17 +586,15 @@ func serveFile(w ResponseWriter, r *Request, fs FileSystem, name string, redirec } } - // redirect if the directory name doesn't end in a slash if d.IsDir() { url := r.URL.Path - if url[len(url)-1] != '/' { + // redirect if the directory name doesn't end in a slash + if url == "" || url[len(url)-1] != '/' { localRedirect(w, r, path.Base(url)+"/") return } - } - // use contents of index.html for directory, if present - if d.IsDir() { + // use contents of index.html for directory, if present index := strings.TrimSuffix(name, "/") + indexPage ff, err := fs.Open(index) if err == nil { @@ -612,7 +614,7 @@ func serveFile(w ResponseWriter, r *Request, fs FileSystem, name string, redirec writeNotModified(w) return } - w.Header().Set("Last-Modified", d.ModTime().UTC().Format(TimeFormat)) + setLastModified(w, d.ModTime()) dirList(w, r, f) return } |