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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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 the index is turned off, we skip the redirect and try_files
|
||||||
if indexFile != "off" {
|
if indexFile != "off" {
|
||||||
dirRedir := false
|
var dirRedir bool
|
||||||
dirIndex := "{http.request.uri.path}/" + indexFile
|
dirIndex := "{http.request.uri.path}/" + indexFile
|
||||||
tryPolicy := "first_exist_fallback"
|
tryPolicy := "first_exist_fallback"
|
||||||
|
|
||||||
@ -328,13 +329,7 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
|
|||||||
tryPolicy = ""
|
tryPolicy = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tf := range tryFiles {
|
dirRedir = slices.Contains(tryFiles, dirIndex)
|
||||||
if tf == dirIndex {
|
|
||||||
dirRedir = true
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if dirRedir {
|
if dirRedir {
|
||||||
|
@ -528,13 +528,7 @@ func (h *HTTPTransport) shouldUseTLS(req *http.Request) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
port := req.URL.Port()
|
port := req.URL.Port()
|
||||||
for i := range h.TLS.ExceptPorts {
|
return !slices.Contains(h.TLS.ExceptPorts, port)
|
||||||
if h.TLS.ExceptPorts[i] == port {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TLSEnabled returns true if TLS is enabled.
|
// TLSEnabled returns true if TLS is enabled.
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
@ -323,13 +324,7 @@ func cmdRespond(fl caddycmd.Flags) (int, error) {
|
|||||||
|
|
||||||
// figure out if status code was explicitly specified; this lets
|
// figure out if status code was explicitly specified; this lets
|
||||||
// us set a non-zero value as the default but is a little hacky
|
// us set a non-zero value as the default but is a little hacky
|
||||||
var statusCodeFlagSpecified bool
|
statusCodeFlagSpecified := slices.Contains(os.Args, "--status")
|
||||||
for _, fl := range os.Args {
|
|
||||||
if fl == "--status" {
|
|
||||||
statusCodeFlagSpecified = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to determine what kind of parameter the unnamed argument is
|
// try to determine what kind of parameter the unnamed argument is
|
||||||
if arg != "" {
|
if arg != "" {
|
||||||
|
@ -87,13 +87,7 @@ nextChoice:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(p.AnyTag) > 0 {
|
if len(p.AnyTag) > 0 {
|
||||||
var found bool
|
found := slices.ContainsFunc(p.AnyTag, cert.HasTag)
|
||||||
for _, tag := range p.AnyTag {
|
|
||||||
if cert.HasTag(tag) {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
if !found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mholt/acmez/v3"
|
"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
|
// ensure ALPN includes the ACME TLS-ALPN protocol
|
||||||
var alpnFound bool
|
alpnFound := slices.Contains(p.ALPN, acmez.ACMETLS1Protocol)
|
||||||
for _, a := range p.ALPN {
|
|
||||||
if a == acmez.ACMETLS1Protocol {
|
|
||||||
alpnFound = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !alpnFound && (cfg.NextProtos == nil || len(cfg.NextProtos) > 0) {
|
if !alpnFound && (cfg.NextProtos == nil || len(cfg.NextProtos) > 0) {
|
||||||
cfg.NextProtos = append(cfg.NextProtos, acmez.ACMETLS1Protocol)
|
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())
|
return fmt.Errorf("can't parse the given certificate: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, trustedLeafCert := range l.trustedLeafCerts {
|
if slices.ContainsFunc(l.trustedLeafCerts, remoteLeafCert.Equal) {
|
||||||
if remoteLeafCert.Equal(trustedLeafCert) {
|
return nil
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("client leaf certificate failed validation")
|
return fmt.Errorf("client leaf certificate failed validation")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user