diff options
| author | apocelipes <seve3r@outlook.com> | 2024-03-21 20:39:28 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-03-21 22:14:00 +0000 |
| commit | 4f0408a3a205a88624dced4b188e11dd429bc3ad (patch) | |
| tree | a7186880ec3434d3859e531a1b3473fe3c16f190 /src/net/http/server.go | |
| parent | 41bd9a517848e4ac2d9d09f48467a0c20a979d43 (diff) | |
| download | go-4f0408a3a205a88624dced4b188e11dd429bc3ad.tar.xz | |
net/http: use slices to simplify the code
"strSliceContains" is replaced by "slices.Contains".
Replace "sort.Strings" with "slices.Sort" since it becomes a wrapper
of "slices.Sort" from Go 1.22.
"headerSorter" no longer has to implement "sort.Interface".
We use "slice.SortFunc" to sort kvs.
Change-Id: Ic29b4c3db147c16079575eca7ad6ff6c0f581188
GitHub-Last-Rev: 78221d5aa223a259a89860b672f39a34897df253
GitHub-Pull-Request: golang/go#66440
Reviewed-on: https://go-review.googlesource.com/c/go/+/573275
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: qiulaidongfeng <2645477756@qq.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'src/net/http/server.go')
| -rw-r--r-- | src/net/http/server.go | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/src/net/http/server.go b/src/net/http/server.go index 31b43606f5..18efbb2ce1 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -23,7 +23,7 @@ import ( urlpkg "net/url" "path" "runtime" - "sort" + "slices" "strconv" "strings" "sync" @@ -2652,7 +2652,7 @@ func (mux *ServeMux) matchingMethods(host, path string) []string { // matchOrRedirect will try appending a trailing slash if there is no match. mux.tree.matchingMethods(host, path+"/", ms) methods := mapKeys(ms) - sort.Strings(methods) + slices.Sort(methods) return methods } @@ -3206,7 +3206,7 @@ func (srv *Server) shouldConfigureHTTP2ForServe() bool { // passed this tls.Config to tls.NewListener. And if they did, // it's too late anyway to fix it. It would only be potentially racy. // See Issue 15908. - return strSliceContains(srv.TLSConfig.NextProtos, http2NextProtoTLS) + return slices.Contains(srv.TLSConfig.NextProtos, http2NextProtoTLS) } // ErrServerClosed is returned by the [Server.Serve], [ServeTLS], [ListenAndServe], @@ -3308,7 +3308,7 @@ func (srv *Server) ServeTLS(l net.Listener, certFile, keyFile string) error { } config := cloneTLSConfig(srv.TLSConfig) - if !strSliceContains(config.NextProtos, "http/1.1") { + if !slices.Contains(config.NextProtos, "http/1.1") { config.NextProtos = append(config.NextProtos, "http/1.1") } @@ -3815,15 +3815,6 @@ func numLeadingCRorLF(v []byte) (n int) { return } -func strSliceContains(ss []string, s string) bool { - for _, v := range ss { - if v == s { - return true - } - } - return false -} - // tlsRecordHeaderLooksLikeHTTP reports whether a TLS record header // looks like it might've been a misdirected plaintext HTTP request. func tlsRecordHeaderLooksLikeHTTP(hdr [5]byte) bool { |
