mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-05-18 19:17:12 +02:00
more string
This commit is contained in:
parent
662d76386c
commit
51ca74fc11
16 changed files with 121 additions and 123 deletions
|
@ -20,7 +20,7 @@ import (
|
|||
)
|
||||
|
||||
// Handler handles a single HTTP request to the web server.
|
||||
func Handler(mainDomainSuffix, rawDomain []byte,
|
||||
func Handler(mainDomainSuffix, rawDomain string,
|
||||
giteaClient *gitea.Client,
|
||||
giteaRoot, rawInfoPage string,
|
||||
blacklistedPaths, allowedCorsDomains []string,
|
||||
|
@ -37,7 +37,7 @@ func Handler(mainDomainSuffix, rawDomain []byte,
|
|||
// Enable browser caching for up to 10 minutes
|
||||
ctx.Response.Header.Set("Cache-Control", "public, max-age=600")
|
||||
|
||||
trimmedHost := utils.TrimHostPort(ctx.Request.Host())
|
||||
trimmedHost := utils.TrimHostPort(string(ctx.Request.Host()))
|
||||
|
||||
// Add HSTS for RawDomain and MainDomainSuffix
|
||||
if hsts := GetHSTSHeader(trimmedHost, mainDomainSuffix, rawDomain); hsts != "" {
|
||||
|
@ -53,7 +53,7 @@ func Handler(mainDomainSuffix, rawDomain []byte,
|
|||
|
||||
// Block blacklisted paths (like ACME challenges)
|
||||
for _, blacklistedPath := range blacklistedPaths {
|
||||
if bytes.HasPrefix(ctx.Path(), []byte(blacklistedPath)) {
|
||||
if strings.HasPrefix(string(ctx.Path()), blacklistedPath) {
|
||||
html.ReturnErrorPage(ctx, fasthttp.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ func Handler(mainDomainSuffix, rawDomain []byte,
|
|||
// Allow CORS for specified domains
|
||||
allowCors := false
|
||||
for _, allowedCorsDomain := range allowedCorsDomains {
|
||||
if bytes.Equal(trimmedHost, []byte(allowedCorsDomain)) {
|
||||
if strings.EqualFold(trimmedHost, allowedCorsDomain) {
|
||||
allowCors = true
|
||||
break
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ func Handler(mainDomainSuffix, rawDomain []byte,
|
|||
}
|
||||
|
||||
log.Debug().Msg("preparations")
|
||||
if rawDomain != nil && bytes.Equal(trimmedHost, rawDomain) {
|
||||
if rawDomain != "" && strings.EqualFold(trimmedHost, rawDomain) {
|
||||
// Serve raw content from RawDomain
|
||||
log.Debug().Msg("raw domain")
|
||||
|
||||
|
@ -172,12 +172,12 @@ func Handler(mainDomainSuffix, rawDomain []byte,
|
|||
canonicalDomainCache)
|
||||
return
|
||||
|
||||
} else if bytes.HasSuffix(trimmedHost, mainDomainSuffix) {
|
||||
} else if strings.HasSuffix(trimmedHost, mainDomainSuffix) {
|
||||
// Serve pages from subdomains of MainDomainSuffix
|
||||
log.Debug().Msg("main domain suffix")
|
||||
|
||||
pathElements := strings.Split(string(bytes.Trim(ctx.Request.URI().Path(), "/")), "/")
|
||||
targetOwner = string(bytes.TrimSuffix(trimmedHost, mainDomainSuffix))
|
||||
pathElements := strings.Split(strings.Trim(string(ctx.Request.URI().Path()), "/"), "/")
|
||||
targetOwner = strings.TrimSuffix(trimmedHost, mainDomainSuffix)
|
||||
targetRepo = pathElements[0]
|
||||
targetPath = strings.Trim(strings.Join(pathElements[1:], "/"), "/")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue