aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/http.go
diff options
context:
space:
mode:
authorJorropo <jorropo.pgm@gmail.com>2025-12-02 05:06:09 +0100
committerGopher Robot <gobot@golang.org>2026-02-06 09:37:27 -0800
commitfc9f22134a870528a7a6d110fa6172431f73cccf (patch)
treedbd929a6cd9f5bfb7df43c6922ceee07fe5840f8 /src/net/http/http.go
parenta72a4295edf694395ba9d3b5e7c5393ebf6a415d (diff)
downloadgo-fc9f22134a870528a7a6d110fa6172431f73cccf.tar.xz
net/http: remove hasPort and simplify logic
Fixes #76651 Change-Id: I306e127375095bc0caedb01ac458107cfec5f085 Reviewed-on: https://go-review.googlesource.com/c/go/+/725740 Auto-Submit: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Sean Liao <sean@liao.dev>
Diffstat (limited to 'src/net/http/http.go')
-rw-r--r--src/net/http/http.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/net/http/http.go b/src/net/http/http.go
index d3e9a2787a..100d4fe4a1 100644
--- a/src/net/http/http.go
+++ b/src/net/http/http.go
@@ -106,15 +106,15 @@ type contextKey struct {
func (k *contextKey) String() string { return "net/http context value " + k.name }
-// Given a string of the form "host", "host:port", or "[ipv6::address]:port",
-// return true if the string includes a port.
-func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
-
-// removeEmptyPort strips the empty port in ":port" to ""
-// as mandated by RFC 3986 Section 6.2.3.
-func removeEmptyPort(host string) string {
- if hasPort(host) {
- return strings.TrimSuffix(host, ":")
+// removePort strips the port while correclty handling IPv6.
+func removePort(host string) string {
+ for i := len(host) - 1; i >= 0; i-- {
+ switch host[i] {
+ case ':':
+ return host[:i]
+ case ']':
+ return host
+ }
}
return host
}