diff options
author | Francis Lavoie <[email protected]> | 2024-09-25 16:30:56 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2024-09-25 14:30:56 -0600 |
commit | 2faeac0a104c72e9396717406ecb7c353bf9aa64 (patch) | |
tree | 5ae5bc9c450f5fb72ad618cac083f4cf8d71d139 /modules/caddyhttp/reverseproxy/httptransport.go | |
parent | 9dda8fbf846db052243e6ce5ab707650da8c030e (diff) | |
download | caddy-2faeac0a104c72e9396717406ecb7c353bf9aa64.tar.gz caddy-2faeac0a104c72e9396717406ecb7c353bf9aa64.zip |
chore: Use slices package where possible (#6585)
* chore: Use slices package where possible
* More, mostly using ContainsFunc
* Even more slice operations
Diffstat (limited to 'modules/caddyhttp/reverseproxy/httptransport.go')
-rw-r--r-- | modules/caddyhttp/reverseproxy/httptransport.go | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/modules/caddyhttp/reverseproxy/httptransport.go b/modules/caddyhttp/reverseproxy/httptransport.go index 144960cf9..bc8233788 100644 --- a/modules/caddyhttp/reverseproxy/httptransport.go +++ b/modules/caddyhttp/reverseproxy/httptransport.go @@ -27,6 +27,7 @@ import ( "net/url" "os" "reflect" + "slices" "strings" "time" @@ -381,7 +382,7 @@ func (h *HTTPTransport) NewTransport(caddyCtx caddy.Context) (*http.Transport, e rt.DisableCompression = !*h.Compression } - if sliceContains(h.Versions, "2") { + if slices.Contains(h.Versions, "2") { if err := http2.ConfigureTransport(rt); err != nil { return nil, err } @@ -400,13 +401,13 @@ func (h *HTTPTransport) NewTransport(caddyCtx caddy.Context) (*http.Transport, e return nil, fmt.Errorf("making TLS client config for HTTP/3 transport: %v", err) } } - } else if len(h.Versions) > 1 && sliceContains(h.Versions, "3") { + } else if len(h.Versions) > 1 && slices.Contains(h.Versions, "3") { return nil, fmt.Errorf("if HTTP/3 is enabled to the upstream, no other HTTP versions are supported") } // if h2c is enabled, configure its transport (std lib http.Transport // does not "HTTP/2 over cleartext TCP") - if sliceContains(h.Versions, "h2c") { + if slices.Contains(h.Versions, "h2c") { // crafting our own http2.Transport doesn't allow us to utilize // most of the customizations/preferences on the http.Transport, // because, for some reason, only http2.ConfigureTransport() @@ -783,16 +784,6 @@ func decodeBase64DERCert(certStr string) (*x509.Certificate, error) { return x509.ParseCertificate(derBytes) } -// sliceContains returns true if needle is in haystack. -func sliceContains(haystack []string, needle string) bool { - for _, s := range haystack { - if s == needle { - return true - } - } - return false -} - // Interface guards var ( _ caddy.Provisioner = (*HTTPTransport)(nil) |