Skip to content

Commit 97158ac

Browse files
authored
Replace Split in loops with more efficient SplitSeq
1 parent a6516d3 commit 97158ac

11 files changed

Lines changed: 15 additions & 15 deletions

File tree

integration/access_log_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ func digestParts(resp *http.Response) map[string]string {
245245
result := map[string]string{}
246246
if len(resp.Header["Www-Authenticate"]) > 0 {
247247
wantedHeaders := []string{"nonce", "realm", "qop", "opaque"}
248-
responseHeaders := strings.Split(resp.Header["Www-Authenticate"][0], ",")
249-
for _, r := range responseHeaders {
248+
responseHeaders := strings.SplitSeq(resp.Header["Www-Authenticate"][0], ",")
249+
for r := range responseHeaders {
250250
for _, w := range wantedHeaders {
251251
if strings.Contains(r, w) {
252252
result[w] = strings.Split(r, `"`)[1]

integration/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ func (s *BaseSuite) displayTraefikLog(output *bytes.Buffer) {
409409
if output == nil || output.Len() == 0 {
410410
log.Info().Msg("No Traefik logs.")
411411
} else {
412-
for _, line := range strings.Split(output.String(), "\n") {
412+
for line := range strings.SplitSeq(output.String(), "\n") {
413413
log.Info().Msg(line)
414414
}
415415
}

pkg/middlewares/accesslog/logger_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func lineCount(t *testing.T, fileName string) int {
325325
}
326326

327327
count := 0
328-
for _, line := range strings.Split(string(fileContents), "\n") {
328+
for line := range strings.SplitSeq(string(fileContents), "\n") {
329329
if strings.TrimSpace(line) == "" {
330330
continue
331331
}

pkg/middlewares/auth/connectionheader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func RemoveConnectionHeaders(req *http.Request) {
2222
}
2323

2424
for _, f := range req.Header[connectionHeader] {
25-
for _, sf := range strings.Split(f, ",") {
25+
for sf := range strings.SplitSeq(f, ",") {
2626
if sf = textproto.TrimString(sf); sf != "" {
2727
req.Header.Del(sf)
2828
}

pkg/middlewares/compress/acceptencoding.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func parseAcceptableEncodings(acceptEncoding []string, supportedEncodings map[st
6363
var encodings []Encoding
6464

6565
for _, line := range acceptEncoding {
66-
for _, item := range strings.Split(strings.ReplaceAll(line, " ", ""), ",") {
66+
for item := range strings.SplitSeq(strings.ReplaceAll(line, " ", ""), ",") {
6767
parsed := strings.SplitN(item, ";", 2)
6868
if len(parsed) == 0 {
6969
continue

pkg/middlewares/forwardedheaders/forwarded_header.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (x *XForwarded) removeConnectionHeaders(req *http.Request) {
216216

217217
var connectionHopByHopHeaders []string
218218
for _, f := range req.Header[connection] {
219-
for _, sf := range strings.Split(f, ",") {
219+
for sf := range strings.SplitSeq(f, ",") {
220220
if sf = textproto.TrimString(sf); sf != "" {
221221
// Connection header cannot dictate to remove X- headers managed by Traefik,
222222
// as per rfc7230 https://datatracker.ietf.org/doc/html/rfc7230#section-6.1,

pkg/provider/acme/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ func (p *Provider) certExists(validDomains []string) bool {
10881088

10891089
func isDomainAlreadyChecked(domainToCheck string, existentDomains []string) bool {
10901090
for _, certDomains := range existentDomains {
1091-
for _, certDomain := range strings.Split(certDomains, ",") {
1091+
for certDomain := range strings.SplitSeq(certDomains, ",") {
10921092
if types.MatchDomain(domainToCheck, certDomain) {
10931093
return true
10941094
}

pkg/provider/kubernetes/ingress-nginx/annotations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ func parseIngressConfig(ing *netv1.Ingress) (ingressConfig, error) {
9292
if field.Type.Elem().Elem().Kind() == reflect.String {
9393
// Handle slice of strings
9494
var slice []string
95-
elements := strings.Split(val, ",")
96-
for _, elt := range elements {
95+
elements := strings.SplitSeq(val, ",")
96+
for elt := range elements {
9797
slice = append(slice, strings.TrimSpace(elt))
9898
}
9999
cfgValue.Field(i).Set(reflect.ValueOf(&slice))

pkg/provider/kubernetes/ingress-nginx/kubernetes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,8 +1128,8 @@ func basicAuthUsers(secret *corev1.Secret, authSecretType string) (dynamic.Users
11281128
}
11291129

11301130
// Trim lines and filter out blanks
1131-
rawLines := strings.Split(string(authFileContent), "\n")
1132-
for _, rawLine := range rawLines {
1131+
rawLines := strings.SplitSeq(string(authFileContent), "\n")
1132+
for rawLine := range rawLines {
11331133
line := strings.TrimSpace(rawLine)
11341134
if line != "" && !strings.HasPrefix(line, "#") {
11351135
users = append(users, line)

pkg/proxy/fast/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ type fasthttpHeader interface {
364364
// See RFC 7230, section 6.1.
365365
func removeConnectionHeaders(h fasthttpHeader) {
366366
f := h.Peek(fasthttp.HeaderConnection)
367-
for _, sf := range bytes.Split(f, []byte{','}) {
367+
for sf := range bytes.SplitSeq(f, []byte{','}) {
368368
if sf = bytes.TrimSpace(sf); len(sf) > 0 {
369369
h.DelBytes(sf)
370370
}

0 commit comments

Comments
 (0)