Skip to content

Commit

Permalink
feat(middleware): serve stale content if not strict
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Oct 15, 2024
1 parent d4e691b commit 4cc253f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n
return err
}

if rfc.ValidateMaxAgeCachedStaleResponse(requestCc, response, int(addTime.Seconds())) != nil {
if !modeContext.Strict || rfc.ValidateMaxAgeCachedStaleResponse(requestCc, response, int(addTime.Seconds())) != nil {
customWriter.WriteHeader(response.StatusCode)
rfc.HitStaleCache(&response.Header)
maps.Copy(customWriter.Header(), response.Header)
Expand Down
2 changes: 1 addition & 1 deletion plugins/traefik/override/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n
return err
}

if rfc.ValidateMaxAgeCachedStaleResponse(requestCc, response, int(addTime.Seconds())) != nil {
if !modeContext.Strict || rfc.ValidateMaxAgeCachedStaleResponse(requestCc, response, int(addTime.Seconds())) != nil {
customWriter.Headers = response.Header
customWriter.statusCode = response.StatusCode
rfc.HitStaleCache(&response.Header)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/tyk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func SouinRequestHandler(rw http.ResponseWriter, baseRq *http.Request) {
return
}

if rfc.ValidateMaxAgeCachedStaleResponse(requestCc, response, int(addTime.Seconds())) != nil {
if !modeContext.Strict || rfc.ValidateMaxAgeCachedStaleResponse(requestCc, response, int(addTime.Seconds())) != nil {
h := response.Header
rfc.HitStaleCache(&h)
for hn, hv := range h {
Expand Down

0 comments on commit 4cc253f

Please sign in to comment.