more string

This commit is contained in:
6543 2022-08-28 16:21:37 +02:00
parent 662d76386c
commit 51ca74fc11
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE
16 changed files with 121 additions and 123 deletions

View file

@ -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:], "/"), "/")