This commit is contained in:
6543 2022-11-12 19:13:54 +01:00
parent 5e499fc12c
commit 6afc95b875
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE

View file

@ -105,12 +105,11 @@ func Handler(mainDomainSuffix, rawDomain string,
if len(pathElements) > 2 && strings.HasPrefix(pathElements[2], "@") { if len(pathElements) > 2 && strings.HasPrefix(pathElements[2], "@") {
log.Debug().Msg("raw domain preparations, now trying with specified branch") log.Debug().Msg("raw domain preparations, now trying with specified branch")
if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{ if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{
TryIndexPages: false, ServeRaw: true,
ServeRaw: true, TargetOwner: pathElements[0],
TargetOwner: pathElements[0], TargetRepo: pathElements[1],
TargetRepo: pathElements[1], TargetBranch: pathElements[2][1:],
TargetBranch: pathElements[2][1:], TargetPath: path.Join(pathElements[3:]...),
TargetPath: path.Join(pathElements[3:]...),
}, true); works { }, true); works {
log.Trace().Msg("tryUpstream: serve raw domain with specified branch") log.Trace().Msg("tryUpstream: serve raw domain with specified branch")
tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOpt, canonicalDomainCache) tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOpt, canonicalDomainCache)
@ -162,10 +161,11 @@ func Handler(mainDomainSuffix, rawDomain string,
log.Debug().Msg("main domain preparations, now trying with specified repo & branch") log.Debug().Msg("main domain preparations, now trying with specified repo & branch")
if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{ if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{
TargetOwner: targetOwner, TryIndexPages: true,
TargetRepo: pathElements[0], TargetOwner: targetOwner,
TargetBranch: pathElements[1][1:], TargetRepo: pathElements[0],
TargetPath: path.Join(pathElements[2:]...), TargetBranch: pathElements[1][1:],
TargetPath: path.Join(pathElements[2:]...),
}, true); works { }, true); works {
log.Trace().Msg("tryUpstream: serve with specified repo and branch") log.Trace().Msg("tryUpstream: serve with specified repo and branch")
tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOpt, canonicalDomainCache) tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOpt, canonicalDomainCache)
@ -182,10 +182,11 @@ func Handler(mainDomainSuffix, rawDomain string,
if strings.HasPrefix(pathElements[0], "@") { if strings.HasPrefix(pathElements[0], "@") {
log.Debug().Msg("main domain preparations, now trying with specified branch") log.Debug().Msg("main domain preparations, now trying with specified branch")
if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{ if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{
TargetOwner: targetOwner, TryIndexPages: true,
TargetRepo: "pages", TargetOwner: targetOwner,
TargetBranch: pathElements[0][1:], TargetRepo: "pages",
TargetPath: path.Join(pathElements[1:]...), TargetBranch: pathElements[0][1:],
TargetPath: path.Join(pathElements[1:]...),
}, true); works { }, true); works {
log.Trace().Msg("tryUpstream: serve default pages repo with specified branch") log.Trace().Msg("tryUpstream: serve default pages repo with specified branch")
tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOpt, canonicalDomainCache) tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOpt, canonicalDomainCache)
@ -203,10 +204,11 @@ func Handler(mainDomainSuffix, rawDomain string,
log.Debug().Msg("main domain preparations, now trying with specified repo") log.Debug().Msg("main domain preparations, now trying with specified repo")
if pathElements[0] != "pages" { if pathElements[0] != "pages" {
if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{ if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{
TargetOwner: targetOwner, TryIndexPages: true,
TargetRepo: pathElements[0], TargetOwner: targetOwner,
TargetBranch: "pages", TargetRepo: pathElements[0],
TargetPath: path.Join(pathElements[1:]...), TargetBranch: "pages",
TargetPath: path.Join(pathElements[1:]...),
}, false); works { }, false); works {
log.Debug().Msg("tryBranch, now trying upstream 5") log.Debug().Msg("tryBranch, now trying upstream 5")
tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOpt, canonicalDomainCache) tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOpt, canonicalDomainCache)
@ -218,9 +220,10 @@ func Handler(mainDomainSuffix, rawDomain string,
// example.codeberg.page/index.html // example.codeberg.page/index.html
log.Debug().Msg("main domain preparations, now trying with default repo/branch") log.Debug().Msg("main domain preparations, now trying with default repo/branch")
if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{ if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{
TargetOwner: targetOwner, TryIndexPages: true,
TargetRepo: "pages", TargetOwner: targetOwner,
TargetPath: path.Join(pathElements...), TargetRepo: "pages",
TargetPath: path.Join(pathElements...),
}, false); works { }, false); works {
log.Debug().Msg("tryBranch, now trying upstream 6") log.Debug().Msg("tryBranch, now trying upstream 6")
tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOpt, canonicalDomainCache) tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOpt, canonicalDomainCache)
@ -255,10 +258,11 @@ func Handler(mainDomainSuffix, rawDomain string,
// Try to use the given repo on the given branch or the default branch // Try to use the given repo on the given branch or the default branch
log.Debug().Msg("custom domain preparations, now trying with details from DNS") log.Debug().Msg("custom domain preparations, now trying with details from DNS")
if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{ if targetOpt, works := tryBranch(log, ctx, giteaClient, &upstream.Options{
TargetOwner: targetOwner, TryIndexPages: true,
TargetRepo: targetRepo, TargetOwner: targetOwner,
TargetBranch: targetBranch, TargetRepo: targetRepo,
TargetPath: path.Join(pathParts...), TargetBranch: targetBranch,
TargetPath: path.Join(pathParts...),
}, canonicalLink); works { }, canonicalLink); works {
canonicalDomain, valid := targetOpt.CheckCanonicalDomain(giteaClient, trimmedHostStr, string(mainDomainSuffix), canonicalDomainCache) canonicalDomain, valid := targetOpt.CheckCanonicalDomain(giteaClient, trimmedHostStr, string(mainDomainSuffix), canonicalDomainCache)
if !valid { if !valid {