summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorWilczyƄskiT <102859171+WilczynskiT@users.noreply.github.com>2022-08-04 19:17:35 +0200
committerGitHub <noreply@github.com>2022-08-04 11:17:35 -0600
commit2642bd72b7ca35b8622824fdffced2aefe1aaf11 (patch)
tree3bc73bada610bfee6377eb58d89ca18b72236966 /modules
parent17ae5acaba536e98cfa86ddcd6967801f1fa1bbe (diff)
Replace strings.Index usages with strings.Cut (#4930)
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/matchers.go6
-rw-r--r--modules/caddyhttp/push/link.go11
-rw-r--r--modules/caddyhttp/reverseproxy/addresses.go6
-rw-r--r--modules/caddyhttp/reverseproxy/fastcgi/client.go8
4 files changed, 15 insertions, 16 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index 2eedaca..bb957d6 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -610,11 +610,11 @@ func (m *MatchQuery) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
if query == "" {
continue
}
- parts := strings.SplitN(query, "=", 2)
- if len(parts) != 2 {
+ before, after, found := strings.Cut(query, "=")
+ if !found {
return d.Errf("malformed query matcher token: %s; must be in param=val format", d.Val())
}
- url.Values(*m).Add(parts[0], parts[1])
+ url.Values(*m).Add(before, after)
}
if d.NextBlock(0) {
return d.Err("malformed query matcher: blocks are not supported")
diff --git a/modules/caddyhttp/push/link.go b/modules/caddyhttp/push/link.go
index 16b0e7d..f7c1dd8 100644
--- a/modules/caddyhttp/push/link.go
+++ b/modules/caddyhttp/push/link.go
@@ -52,17 +52,16 @@ func parseLinkHeader(header string) []linkResource {
l.uri = strings.TrimSpace(link[li+1 : ri])
for _, param := range strings.Split(strings.TrimSpace(link[ri+1:]), semicolon) {
- parts := strings.SplitN(strings.TrimSpace(param), equal, 2)
- key := strings.TrimSpace(parts[0])
+ before, after, isCut := strings.Cut(strings.TrimSpace(param), equal)
+ key := strings.TrimSpace(before)
if key == "" {
continue
}
- if len(parts) == 1 {
+ if isCut {
+ l.params[key] = strings.TrimSpace(after)
+ } else {
l.params[key] = key
}
- if len(parts) == 2 {
- l.params[key] = strings.TrimSpace(parts[1])
- }
}
resources = append(resources, l)
diff --git a/modules/caddyhttp/reverseproxy/addresses.go b/modules/caddyhttp/reverseproxy/addresses.go
index f15ed76..c161ed8 100644
--- a/modules/caddyhttp/reverseproxy/addresses.go
+++ b/modules/caddyhttp/reverseproxy/addresses.go
@@ -80,9 +80,9 @@ func parseUpstreamDialAddress(upstreamAddr string) (string, string, error) {
scheme, host, port = toURL.Scheme, toURL.Hostname(), toURL.Port()
} else {
// extract network manually, since caddy.ParseNetworkAddress() will always add one
- if idx := strings.Index(upstreamAddr, "/"); idx >= 0 {
- network = strings.ToLower(strings.TrimSpace(upstreamAddr[:idx]))
- upstreamAddr = upstreamAddr[idx+1:]
+ if beforeSlash, afterSlash, slashFound := strings.Cut(upstreamAddr, "/"); slashFound {
+ network = strings.ToLower(strings.TrimSpace(beforeSlash))
+ upstreamAddr = afterSlash
}
var err error
host, port, err = net.SplitHostPort(upstreamAddr)
diff --git a/modules/caddyhttp/reverseproxy/fastcgi/client.go b/modules/caddyhttp/reverseproxy/fastcgi/client.go
index 0772053..0fdcbfe 100644
--- a/modules/caddyhttp/reverseproxy/fastcgi/client.go
+++ b/modules/caddyhttp/reverseproxy/fastcgi/client.go
@@ -424,13 +424,13 @@ func (c *FCGIClient) Request(p map[string]string, req io.Reader) (resp *http.Res
resp.Header = http.Header(mimeHeader)
if resp.Header.Get("Status") != "" {
- statusParts := strings.SplitN(resp.Header.Get("Status"), " ", 2)
- resp.StatusCode, err = strconv.Atoi(statusParts[0])
+ statusNumber, statusInfo, statusIsCut := strings.Cut(resp.Header.Get("Status"), " ")
+ resp.StatusCode, err = strconv.Atoi(statusNumber)
if err != nil {
return
}
- if len(statusParts) > 1 {
- resp.Status = statusParts[1]
+ if statusIsCut {
+ resp.Status = statusInfo
}
} else {