Skip to content

Commit

Permalink
fix(rfc): Last-Modified handling #588
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Dec 26, 2024
1 parent cae85ee commit bcca550
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,17 @@ func (s *SouinBaseHandler) Revalidate(validator *core.Revalidator, next handlerF
return nil, errors.New("")
}

if validator.IfModifiedSincePresent {
if lastModified, err := time.Parse(time.RFC1123, customWriter.Header().Get("Last-Modified")); err == nil && validator.IfModifiedSince.Sub(lastModified) > 0 {
customWriter.handleBuffer(func(b *bytes.Buffer) {
b.Reset()
})
customWriter.Rw.WriteHeader(http.StatusNotModified)

return nil, errors.New("")
}
}

if statusCode != http.StatusNotModified {
err = s.Store(customWriter, rq, requestCc, cachedKey, uri)
}
Expand Down

0 comments on commit bcca550

Please sign in to comment.