...

Source file src/github.com/linkerd/linkerd2/web/srv/reverse_proxy.go

Documentation: github.com/linkerd/linkerd2/web/srv

     1  package srv
     2  
     3  import (
     4  	"net/http"
     5  	"net/http/httputil"
     6  	"strings"
     7  )
     8  
     9  // reverseProxy is an HTTP reverse proxy that forwards all web requests
    10  // containing paths prefixed  to the corresponding service. The proxy
    11  // strips the prefix and rewrites the Host header before sending.
    12  type reverseProxy struct {
    13  	*httputil.ReverseProxy
    14  }
    15  
    16  func newReverseProxy(addr string, prefix string) *reverseProxy {
    17  	director := func(req *http.Request) {
    18  		req.URL.Host = addr
    19  		req.URL.Scheme = "http"
    20  		req.URL.Path = strings.TrimPrefix(req.URL.Path, prefix)
    21  
    22  		// the default director implementation does this, so we will too
    23  		if _, ok := req.Header["User-Agent"]; !ok {
    24  			// explicitly disable User-Agent so it's not set to default value
    25  			req.Header.Set("User-Agent", "")
    26  		}
    27  	}
    28  
    29  	return &reverseProxy{
    30  		ReverseProxy: &httputil.ReverseProxy{Director: director},
    31  	}
    32  }
    33  

View as plain text