mirror of
https://github.com/caddyserver/caddy.git
synced 2025-07-09 03:04:57 -04:00
Use slices.Contains to simplify code (#7039)
Some checks failed
Tests / test (./cmd/caddy/caddy, ~1.24.1, ubuntu-latest, 0, 1.24, linux) (push) Failing after 2m25s
Tests / test (s390x on IBM Z) (push) Has been skipped
Tests / goreleaser-check (push) Has been skipped
Cross-Build / build (~1.24.1, 1.24, aix) (push) Successful in 1m27s
Cross-Build / build (~1.24.1, 1.24, darwin) (push) Successful in 1m21s
Cross-Build / build (~1.24.1, 1.24, dragonfly) (push) Successful in 1m24s
Cross-Build / build (~1.24.1, 1.24, freebsd) (push) Successful in 1m25s
Cross-Build / build (~1.24.1, 1.24, illumos) (push) Successful in 1m19s
Cross-Build / build (~1.24.1, 1.24, linux) (push) Successful in 1m20s
Cross-Build / build (~1.24.1, 1.24, netbsd) (push) Successful in 1m21s
Cross-Build / build (~1.24.1, 1.24, openbsd) (push) Successful in 1m17s
Cross-Build / build (~1.24.1, 1.24, solaris) (push) Successful in 1m18s
Cross-Build / build (~1.24.1, 1.24, windows) (push) Successful in 1m23s
Lint / lint (ubuntu-latest, linux) (push) Successful in 2m17s
Lint / govulncheck (push) Successful in 1m43s
Tests / test (./cmd/caddy/caddy, ~1.24.1, macos-14, 0, 1.24, mac) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy.exe, ~1.24.1, windows-latest, True, 1.24, windows) (push) Has been cancelled
Lint / lint (macos-14, mac) (push) Has been cancelled
Lint / lint (windows-latest, windows) (push) Has been cancelled
Some checks failed
Tests / test (./cmd/caddy/caddy, ~1.24.1, ubuntu-latest, 0, 1.24, linux) (push) Failing after 2m25s
Tests / test (s390x on IBM Z) (push) Has been skipped
Tests / goreleaser-check (push) Has been skipped
Cross-Build / build (~1.24.1, 1.24, aix) (push) Successful in 1m27s
Cross-Build / build (~1.24.1, 1.24, darwin) (push) Successful in 1m21s
Cross-Build / build (~1.24.1, 1.24, dragonfly) (push) Successful in 1m24s
Cross-Build / build (~1.24.1, 1.24, freebsd) (push) Successful in 1m25s
Cross-Build / build (~1.24.1, 1.24, illumos) (push) Successful in 1m19s
Cross-Build / build (~1.24.1, 1.24, linux) (push) Successful in 1m20s
Cross-Build / build (~1.24.1, 1.24, netbsd) (push) Successful in 1m21s
Cross-Build / build (~1.24.1, 1.24, openbsd) (push) Successful in 1m17s
Cross-Build / build (~1.24.1, 1.24, solaris) (push) Successful in 1m18s
Cross-Build / build (~1.24.1, 1.24, windows) (push) Successful in 1m23s
Lint / lint (ubuntu-latest, linux) (push) Successful in 2m17s
Lint / govulncheck (push) Successful in 1m43s
Tests / test (./cmd/caddy/caddy, ~1.24.1, macos-14, 0, 1.24, mac) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy.exe, ~1.24.1, windows-latest, True, 1.24, windows) (push) Has been cancelled
Lint / lint (macos-14, mac) (push) Has been cancelled
Lint / lint (windows-latest, windows) (push) Has been cancelled
Signed-off-by: tongjicoder <tongjicoder@icloud.com>
This commit is contained in:
parent
a76d005a94
commit
5b2eb66418
@ -17,6 +17,7 @@ package fastcgi
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -314,7 +315,7 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
|
||||
|
||||
// if the index is turned off, we skip the redirect and try_files
|
||||
if indexFile != "off" {
|
||||
dirRedir := false
|
||||
var dirRedir bool
|
||||
dirIndex := "{http.request.uri.path}/" + indexFile
|
||||
tryPolicy := "first_exist_fallback"
|
||||
|
||||
@ -328,13 +329,7 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
|
||||
tryPolicy = ""
|
||||
}
|
||||
|
||||
for _, tf := range tryFiles {
|
||||
if tf == dirIndex {
|
||||
dirRedir = true
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
dirRedir = slices.Contains(tryFiles, dirIndex)
|
||||
}
|
||||
|
||||
if dirRedir {
|
||||
|
@ -528,13 +528,7 @@ func (h *HTTPTransport) shouldUseTLS(req *http.Request) bool {
|
||||
}
|
||||
|
||||
port := req.URL.Port()
|
||||
for i := range h.TLS.ExceptPorts {
|
||||
if h.TLS.ExceptPorts[i] == port {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
return !slices.Contains(h.TLS.ExceptPorts, port)
|
||||
}
|
||||
|
||||
// TLSEnabled returns true if TLS is enabled.
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"net/http"
|
||||
"net/textproto"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
@ -323,13 +324,7 @@ func cmdRespond(fl caddycmd.Flags) (int, error) {
|
||||
|
||||
// figure out if status code was explicitly specified; this lets
|
||||
// us set a non-zero value as the default but is a little hacky
|
||||
var statusCodeFlagSpecified bool
|
||||
for _, fl := range os.Args {
|
||||
if fl == "--status" {
|
||||
statusCodeFlagSpecified = true
|
||||
break
|
||||
}
|
||||
}
|
||||
statusCodeFlagSpecified := slices.Contains(os.Args, "--status")
|
||||
|
||||
// try to determine what kind of parameter the unnamed argument is
|
||||
if arg != "" {
|
||||
|
@ -87,13 +87,7 @@ nextChoice:
|
||||
}
|
||||
|
||||
if len(p.AnyTag) > 0 {
|
||||
var found bool
|
||||
for _, tag := range p.AnyTag {
|
||||
if cert.HasTag(tag) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
found := slices.ContainsFunc(p.AnyTag, cert.HasTag)
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/mholt/acmez/v3"
|
||||
@ -369,13 +370,7 @@ func (p *ConnectionPolicy) buildStandardTLSConfig(ctx caddy.Context) error {
|
||||
}
|
||||
|
||||
// ensure ALPN includes the ACME TLS-ALPN protocol
|
||||
var alpnFound bool
|
||||
for _, a := range p.ALPN {
|
||||
if a == acmez.ACMETLS1Protocol {
|
||||
alpnFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
alpnFound := slices.Contains(p.ALPN, acmez.ACMETLS1Protocol)
|
||||
if !alpnFound && (cfg.NextProtos == nil || len(cfg.NextProtos) > 0) {
|
||||
cfg.NextProtos = append(cfg.NextProtos, acmez.ACMETLS1Protocol)
|
||||
}
|
||||
@ -1004,10 +999,8 @@ func (l LeafCertClientAuth) VerifyClientCertificate(rawCerts [][]byte, _ [][]*x5
|
||||
return fmt.Errorf("can't parse the given certificate: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, trustedLeafCert := range l.trustedLeafCerts {
|
||||
if remoteLeafCert.Equal(trustedLeafCert) {
|
||||
return nil
|
||||
}
|
||||
if slices.ContainsFunc(l.trustedLeafCerts, remoteLeafCert.Equal) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("client leaf certificate failed validation")
|
||||
|
Loading…
x
Reference in New Issue
Block a user