aboutsummaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/util/net/http.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/util/net/http.go')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/net/http.go49
1 files changed, 35 insertions, 14 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/util/net/http.go b/vendor/k8s.io/apimachinery/pkg/util/net/http.go
index adb80813b..bc2a531b9 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/net/http.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/net/http.go
@@ -26,6 +26,7 @@ import (
"net/http"
"net/url"
"os"
+ "path"
"strconv"
"strings"
@@ -33,6 +34,26 @@ import (
"golang.org/x/net/http2"
)
+// JoinPreservingTrailingSlash does a path.Join of the specified elements,
+// preserving any trailing slash on the last non-empty segment
+func JoinPreservingTrailingSlash(elem ...string) string {
+ // do the basic path join
+ result := path.Join(elem...)
+
+ // find the last non-empty segment
+ for i := len(elem) - 1; i >= 0; i-- {
+ if len(elem[i]) > 0 {
+ // if the last segment ended in a slash, ensure our result does as well
+ if strings.HasSuffix(elem[i], "/") && !strings.HasSuffix(result, "/") {
+ result += "/"
+ }
+ break
+ }
+ }
+
+ return result
+}
+
// IsProbableEOF returns true if the given error resembles a connection termination
// scenario that would justify assuming that the watch is empty.
// These errors are what the Go http stack returns back to us which are general
@@ -108,7 +129,7 @@ func DialerFor(transport http.RoundTripper) (DialFunc, error) {
case RoundTripperWrapper:
return DialerFor(transport.WrappedRoundTripper())
default:
- return nil, fmt.Errorf("unknown transport type: %v", transport)
+ return nil, fmt.Errorf("unknown transport type: %T", transport)
}
}
@@ -129,7 +150,7 @@ func TLSClientConfig(transport http.RoundTripper) (*tls.Config, error) {
case RoundTripperWrapper:
return TLSClientConfig(transport.WrappedRoundTripper())
default:
- return nil, fmt.Errorf("unknown transport type: %v", transport)
+ return nil, fmt.Errorf("unknown transport type: %T", transport)
}
}
@@ -235,8 +256,11 @@ func isDefault(transportProxier func(*http.Request) (*url.URL, error)) bool {
// NewProxierWithNoProxyCIDR constructs a Proxier function that respects CIDRs in NO_PROXY and delegates if
// no matching CIDRs are found
func NewProxierWithNoProxyCIDR(delegate func(req *http.Request) (*url.URL, error)) func(req *http.Request) (*url.URL, error) {
- // we wrap the default method, so we only need to perform our check if the NO_PROXY envvar has a CIDR in it
+ // we wrap the default method, so we only need to perform our check if the NO_PROXY (or no_proxy) envvar has a CIDR in it
noProxyEnv := os.Getenv("NO_PROXY")
+ if noProxyEnv == "" {
+ noProxyEnv = os.Getenv("no_proxy")
+ }
noProxyRules := strings.Split(noProxyEnv, ",")
cidrs := []*net.IPNet{}
@@ -252,17 +276,7 @@ func NewProxierWithNoProxyCIDR(delegate func(req *http.Request) (*url.URL, error
}
return func(req *http.Request) (*url.URL, error) {
- host := req.URL.Host
- // for some urls, the Host is already the host, not the host:port
- if net.ParseIP(host) == nil {
- var err error
- host, _, err = net.SplitHostPort(req.URL.Host)
- if err != nil {
- return delegate(req)
- }
- }
-
- ip := net.ParseIP(host)
+ ip := net.ParseIP(req.URL.Hostname())
if ip == nil {
return delegate(req)
}
@@ -277,6 +291,13 @@ func NewProxierWithNoProxyCIDR(delegate func(req *http.Request) (*url.URL, error
}
}
+// DialerFunc implements Dialer for the provided function.
+type DialerFunc func(req *http.Request) (net.Conn, error)
+
+func (fn DialerFunc) Dial(req *http.Request) (net.Conn, error) {
+ return fn(req)
+}
+
// Dialer dials a host and writes a request to it.
type Dialer interface {
// Dial connects to the host specified by req's URL, writes the request to the connection, and