bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/util/proxy.go (about) 1 package util 2 3 import ( 4 "net/http" 5 "net/http/httputil" 6 "net/url" 7 ) 8 9 // Creates a new http Proxy that forwards requests to the specified url. 10 // Differs from httputil.NewSingleHostReverseProxy only in that it properly sets the host header. 11 func NewSingleHostProxy(target *url.URL) *httputil.ReverseProxy { 12 proxy := httputil.NewSingleHostReverseProxy(target) 13 director := func(req *http.Request) { 14 proxy.Director(req) 15 req.Host = target.Host 16 } 17 return &httputil.ReverseProxy{Director: director} 18 }