1
0
mirror of https://github.com/golang/go synced 2024-11-17 18:04:48 -07:00

net/http: use time.Compare

Change-Id: I4730673130bdfbda9987dcb5869f421082f92150
Reviewed-on: https://go-review.googlesource.com/c/go/+/435615
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
This commit is contained in:
cuiweixie 2022-09-28 08:23:21 +08:00 committed by Gopher Robot
parent 27d4cdd1a6
commit 879f595f7e
2 changed files with 4 additions and 4 deletions

View File

@ -214,8 +214,8 @@ func (j *Jar) cookies(u *url.URL, now time.Time) (cookies []*http.Cookie) {
if len(s[i].Path) != len(s[j].Path) {
return len(s[i].Path) > len(s[j].Path)
}
if !s[i].Creation.Equal(s[j].Creation) {
return s[i].Creation.Before(s[j].Creation)
if ret := s[i].Creation.Compare(s[j].Creation); ret != 0 {
return ret < 0
}
return s[i].seqNum < s[j].seqNum
})

View File

@ -431,7 +431,7 @@ func checkIfUnmodifiedSince(r *Request, modtime time.Time) condResult {
// 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) {
if ret := modtime.Compare(t); ret <= 0 {
return condTrue
}
return condFalse
@ -482,7 +482,7 @@ func checkIfModifiedSince(r *Request, modtime time.Time) condResult {
// 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) {
if ret := modtime.Compare(t); ret <= 0 {
return condFalse
}
return condTrue