Skip to content

Commit

Permalink
fix(now context): caddyserver/cache-handler#116
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Dec 22, 2024
1 parent 00c4b70 commit ed12ace
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions context/now.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ func (*nowContext) SetContextWithBaseRequest(req *http.Request, _ *http.Request)
func (cc *nowContext) SetupContext(_ configurationtypes.AbstractConfigurationInterface) {}

func (cc *nowContext) SetContext(req *http.Request) *http.Request {
now := time.Now().UTC()
req.Header.Set("Date", now.Format(time.RFC1123))
var now time.Time
var e error

now, e = time.Parse(time.RFC1123, req.Header.Get("Date"))

if e != nil {
now := time.Now()

This comment has been minimized.

Copy link
@imlonghao

imlonghao Dec 23, 2024

Contributor

Is it on purpose to use :=?
In this case, it will remain unset when return.

https://go.dev/play/p/-br5etSvh20

req.Header.Set("Date", now.Format(time.RFC1123))
}

return req.WithContext(context.WithValue(req.Context(), Now, now))
}

Expand Down

0 comments on commit ed12ace

Please sign in to comment.