github.com/oam-dev/cluster-gateway@v1.9.0/pkg/apis/cluster/transport/prependroundtripper.go (about) 1 package multicluster 2 3 import "net/http" 4 5 var _ ProxyPathPrependingClusterGatewayRoundTripper = &proxyPathPrependingClusterGatewayRoundTripper{} 6 7 type ProxyPathPrependingClusterGatewayRoundTripper interface { 8 http.RoundTripper 9 10 NewRoundTripper(delegate http.RoundTripper) http.RoundTripper 11 } 12 13 type proxyPathPrependingClusterGatewayRoundTripper struct { 14 clusterName string 15 delegate http.RoundTripper 16 } 17 18 func NewProxyPathPrependingClusterGatewayRoundTripper(clusterName string) ProxyPathPrependingClusterGatewayRoundTripper { 19 return &proxyPathPrependingClusterGatewayRoundTripper{clusterName: clusterName} 20 } 21 22 func (p *proxyPathPrependingClusterGatewayRoundTripper) NewRoundTripper(delegate http.RoundTripper) http.RoundTripper { 23 p.delegate = delegate 24 return p 25 } 26 27 func (p *proxyPathPrependingClusterGatewayRoundTripper) RoundTrip(request *http.Request) (*http.Response, error) { 28 request.URL.Path = formatProxyURL(p.clusterName, request.URL.Path) 29 return p.delegate.RoundTrip(request) 30 }