Fix stack overflow on root redirects (#414)

Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/414
Co-authored-by: crapStone <me@crapstone.dev>
Co-committed-by: crapStone <me@crapstone.dev>
This commit is contained in:
crapStone 2024-12-29 19:01:08 +00:00 committed by crapStone
parent ef7e2cd7bb
commit 6376bfd2e0

View file

@ -92,8 +92,9 @@ func (o *Options) matchRedirects(ctx *context.Context, giteaClient *gitea.Client
for _, redirect := range redirects {
if dstURL, ok := redirect.rewriteURL(reqURL); ok {
// do rewrite if status code is 200
if redirect.StatusCode == 200 {
if o.TargetPath == dstURL { // recursion base case, rewrite directly when paths are the same
return true
} else if redirect.StatusCode == 200 { // do rewrite if status code is 200
o.TargetPath = dstURL
o.Upstream(ctx, giteaClient, redirectsCache)
} else {