aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/internal
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-09-22 10:46:32 -0400
committerRuss Cox <rsc@golang.org>2021-10-06 15:53:04 +0000
commit4d8db00641cc9ff4f44de7df9b8c4f4a4f9416ee (patch)
tree1e850efb295d4c5f0589e46bd8d9f1930d4af0b5 /src/net/http/internal
parent8e36ab055162efa6f67f3b9ee62f625ac8874901 (diff)
downloadgo-4d8db00641cc9ff4f44de7df9b8c4f4a4f9416ee.tar.xz
all: use bytes.Cut, strings.Cut
Many uses of Index/IndexByte/IndexRune/Split/SplitN can be written more clearly using the new Cut functions. Do that. Also rewrite to other functions if that's clearer. For #46336. Change-Id: I68d024716ace41a57a8bf74455c62279bde0f448 Reviewed-on: https://go-review.googlesource.com/c/go/+/351711 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net/http/internal')
-rw-r--r--src/net/http/internal/chunked.go9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/net/http/internal/chunked.go b/src/net/http/internal/chunked.go
index f06e5725f3..923e6a6d2c 100644
--- a/src/net/http/internal/chunked.go
+++ b/src/net/http/internal/chunked.go
@@ -152,6 +152,8 @@ func isASCIISpace(b byte) bool {
return b == ' ' || b == '\t' || b == '\n' || b == '\r'
}
+var semi = []byte(";")
+
// removeChunkExtension removes any chunk-extension from p.
// For example,
// "0" => "0"
@@ -159,14 +161,11 @@ func isASCIISpace(b byte) bool {
// "0;token=val" => "0"
// `0;token="quoted string"` => "0"
func removeChunkExtension(p []byte) ([]byte, error) {
- semi := bytes.IndexByte(p, ';')
- if semi == -1 {
- return p, nil
- }
+ p, _, _ = bytes.Cut(p, semi)
// TODO: care about exact syntax of chunk extensions? We're
// ignoring and stripping them anyway. For now just never
// return an error.
- return p[:semi], nil
+ return p, nil
}
// NewChunkedWriter returns a new chunkedWriter that translates writes into HTTP