mirror of
https://github.com/traefik/traefik.git
synced 2026-02-03 20:39:51 -05:00
Replace Split in loops with more efficient SplitSeq
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Build and Publish Documentation / Doc Process (push) Waiting to run
Build experimental image on branch / build-webui (push) Waiting to run
Build experimental image on branch / Build experimental image on branch (push) Waiting to run
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Build and Publish Documentation / Doc Process (push) Waiting to run
Build experimental image on branch / build-webui (push) Waiting to run
Build experimental image on branch / Build experimental image on branch (push) Waiting to run
This commit is contained in:
parent
a6516d36eb
commit
97158ac770
11 changed files with 15 additions and 15 deletions
|
|
@ -245,8 +245,8 @@ func digestParts(resp *http.Response) map[string]string {
|
||||||
result := map[string]string{}
|
result := map[string]string{}
|
||||||
if len(resp.Header["Www-Authenticate"]) > 0 {
|
if len(resp.Header["Www-Authenticate"]) > 0 {
|
||||||
wantedHeaders := []string{"nonce", "realm", "qop", "opaque"}
|
wantedHeaders := []string{"nonce", "realm", "qop", "opaque"}
|
||||||
responseHeaders := strings.Split(resp.Header["Www-Authenticate"][0], ",")
|
responseHeaders := strings.SplitSeq(resp.Header["Www-Authenticate"][0], ",")
|
||||||
for _, r := range responseHeaders {
|
for r := range responseHeaders {
|
||||||
for _, w := range wantedHeaders {
|
for _, w := range wantedHeaders {
|
||||||
if strings.Contains(r, w) {
|
if strings.Contains(r, w) {
|
||||||
result[w] = strings.Split(r, `"`)[1]
|
result[w] = strings.Split(r, `"`)[1]
|
||||||
|
|
|
||||||
|
|
@ -409,7 +409,7 @@ func (s *BaseSuite) displayTraefikLog(output *bytes.Buffer) {
|
||||||
if output == nil || output.Len() == 0 {
|
if output == nil || output.Len() == 0 {
|
||||||
log.Info().Msg("No Traefik logs.")
|
log.Info().Msg("No Traefik logs.")
|
||||||
} else {
|
} else {
|
||||||
for _, line := range strings.Split(output.String(), "\n") {
|
for line := range strings.SplitSeq(output.String(), "\n") {
|
||||||
log.Info().Msg(line)
|
log.Info().Msg(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -325,7 +325,7 @@ func lineCount(t *testing.T, fileName string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
for _, line := range strings.Split(string(fileContents), "\n") {
|
for line := range strings.SplitSeq(string(fileContents), "\n") {
|
||||||
if strings.TrimSpace(line) == "" {
|
if strings.TrimSpace(line) == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ func RemoveConnectionHeaders(req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range req.Header[connectionHeader] {
|
for _, f := range req.Header[connectionHeader] {
|
||||||
for _, sf := range strings.Split(f, ",") {
|
for sf := range strings.SplitSeq(f, ",") {
|
||||||
if sf = textproto.TrimString(sf); sf != "" {
|
if sf = textproto.TrimString(sf); sf != "" {
|
||||||
req.Header.Del(sf)
|
req.Header.Del(sf)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ func parseAcceptableEncodings(acceptEncoding []string, supportedEncodings map[st
|
||||||
var encodings []Encoding
|
var encodings []Encoding
|
||||||
|
|
||||||
for _, line := range acceptEncoding {
|
for _, line := range acceptEncoding {
|
||||||
for _, item := range strings.Split(strings.ReplaceAll(line, " ", ""), ",") {
|
for item := range strings.SplitSeq(strings.ReplaceAll(line, " ", ""), ",") {
|
||||||
parsed := strings.SplitN(item, ";", 2)
|
parsed := strings.SplitN(item, ";", 2)
|
||||||
if len(parsed) == 0 {
|
if len(parsed) == 0 {
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ func (x *XForwarded) removeConnectionHeaders(req *http.Request) {
|
||||||
|
|
||||||
var connectionHopByHopHeaders []string
|
var connectionHopByHopHeaders []string
|
||||||
for _, f := range req.Header[connection] {
|
for _, f := range req.Header[connection] {
|
||||||
for _, sf := range strings.Split(f, ",") {
|
for sf := range strings.SplitSeq(f, ",") {
|
||||||
if sf = textproto.TrimString(sf); sf != "" {
|
if sf = textproto.TrimString(sf); sf != "" {
|
||||||
// Connection header cannot dictate to remove X- headers managed by Traefik,
|
// Connection header cannot dictate to remove X- headers managed by Traefik,
|
||||||
// as per rfc7230 https://datatracker.ietf.org/doc/html/rfc7230#section-6.1,
|
// as per rfc7230 https://datatracker.ietf.org/doc/html/rfc7230#section-6.1,
|
||||||
|
|
|
||||||
|
|
@ -1088,7 +1088,7 @@ func (p *Provider) certExists(validDomains []string) bool {
|
||||||
|
|
||||||
func isDomainAlreadyChecked(domainToCheck string, existentDomains []string) bool {
|
func isDomainAlreadyChecked(domainToCheck string, existentDomains []string) bool {
|
||||||
for _, certDomains := range existentDomains {
|
for _, certDomains := range existentDomains {
|
||||||
for _, certDomain := range strings.Split(certDomains, ",") {
|
for certDomain := range strings.SplitSeq(certDomains, ",") {
|
||||||
if types.MatchDomain(domainToCheck, certDomain) {
|
if types.MatchDomain(domainToCheck, certDomain) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,8 +92,8 @@ func parseIngressConfig(ing *netv1.Ingress) (ingressConfig, error) {
|
||||||
if field.Type.Elem().Elem().Kind() == reflect.String {
|
if field.Type.Elem().Elem().Kind() == reflect.String {
|
||||||
// Handle slice of strings
|
// Handle slice of strings
|
||||||
var slice []string
|
var slice []string
|
||||||
elements := strings.Split(val, ",")
|
elements := strings.SplitSeq(val, ",")
|
||||||
for _, elt := range elements {
|
for elt := range elements {
|
||||||
slice = append(slice, strings.TrimSpace(elt))
|
slice = append(slice, strings.TrimSpace(elt))
|
||||||
}
|
}
|
||||||
cfgValue.Field(i).Set(reflect.ValueOf(&slice))
|
cfgValue.Field(i).Set(reflect.ValueOf(&slice))
|
||||||
|
|
|
||||||
|
|
@ -1128,8 +1128,8 @@ func basicAuthUsers(secret *corev1.Secret, authSecretType string) (dynamic.Users
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim lines and filter out blanks
|
// Trim lines and filter out blanks
|
||||||
rawLines := strings.Split(string(authFileContent), "\n")
|
rawLines := strings.SplitSeq(string(authFileContent), "\n")
|
||||||
for _, rawLine := range rawLines {
|
for rawLine := range rawLines {
|
||||||
line := strings.TrimSpace(rawLine)
|
line := strings.TrimSpace(rawLine)
|
||||||
if line != "" && !strings.HasPrefix(line, "#") {
|
if line != "" && !strings.HasPrefix(line, "#") {
|
||||||
users = append(users, line)
|
users = append(users, line)
|
||||||
|
|
|
||||||
|
|
@ -364,7 +364,7 @@ type fasthttpHeader interface {
|
||||||
// See RFC 7230, section 6.1.
|
// See RFC 7230, section 6.1.
|
||||||
func removeConnectionHeaders(h fasthttpHeader) {
|
func removeConnectionHeaders(h fasthttpHeader) {
|
||||||
f := h.Peek(fasthttp.HeaderConnection)
|
f := h.Peek(fasthttp.HeaderConnection)
|
||||||
for _, sf := range bytes.Split(f, []byte{','}) {
|
for sf := range bytes.SplitSeq(f, []byte{','}) {
|
||||||
if sf = bytes.TrimSpace(sf); len(sf) > 0 {
|
if sf = bytes.TrimSpace(sf); len(sf) > 0 {
|
||||||
h.DelBytes(sf)
|
h.DelBytes(sf)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ func (c *CertificateStore) GetBestCertificate(clientHello *tls.ClientHelloInfo)
|
||||||
matchedCerts := map[string]*CertificateData{}
|
matchedCerts := map[string]*CertificateData{}
|
||||||
if c.DynamicCerts != nil && c.DynamicCerts.Get() != nil {
|
if c.DynamicCerts != nil && c.DynamicCerts.Get() != nil {
|
||||||
for domains, cert := range c.DynamicCerts.Get().(map[string]*CertificateData) {
|
for domains, cert := range c.DynamicCerts.Get().(map[string]*CertificateData) {
|
||||||
for _, certDomain := range strings.Split(domains, ",") {
|
for certDomain := range strings.SplitSeq(domains, ",") {
|
||||||
if matchDomain(serverName, certDomain) {
|
if matchDomain(serverName, certDomain) {
|
||||||
matchedCerts[certDomain] = cert
|
matchedCerts[certDomain] = cert
|
||||||
}
|
}
|
||||||
|
|
@ -157,7 +157,7 @@ func (c *CertificateStore) GetCertificate(domains []string) *CertificateData {
|
||||||
}
|
}
|
||||||
|
|
||||||
var matchedDomains []string
|
var matchedDomains []string
|
||||||
for _, certDomain := range strings.Split(certDomains, ",") {
|
for certDomain := range strings.SplitSeq(certDomains, ",") {
|
||||||
for _, checkDomain := range domains {
|
for _, checkDomain := range domains {
|
||||||
if certDomain == checkDomain {
|
if certDomain == checkDomain {
|
||||||
matchedDomains = append(matchedDomains, certDomain)
|
matchedDomains = append(matchedDomains, certDomain)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue