udpate modifyProxiedRequest

This commit is contained in:
tuhao 2021-01-22 01:11:25 +08:00
parent 6c823e4864
commit cc69d05727

View File

@ -22,6 +22,7 @@ import (
func ProxyHandler(target *url.URL) *httputil.ReverseProxy { func ProxyHandler(target *url.URL) *httputil.ReverseProxy {
director := func(req *http.Request) { director := func(req *http.Request) {
modifyProxiedRequest(req, target) modifyProxiedRequest(req, target)
req.Host = target.Host
req.URL.Path = path.Join(target.Path, req.URL.Path) req.URL.Path = path.Join(target.Path, req.URL.Path)
} }
@ -40,7 +41,6 @@ func ProxyHandler(target *url.URL) *httputil.ReverseProxy {
func modifyProxiedRequest(req *http.Request, target *url.URL) { func modifyProxiedRequest(req *http.Request, target *url.URL) {
req.URL.Scheme = target.Scheme req.URL.Scheme = target.Scheme
req.URL.Host = target.Host req.URL.Host = target.Host
req.Host = target.Host
if target.RawQuery == "" || req.URL.RawQuery == "" { if target.RawQuery == "" || req.URL.RawQuery == "" {
req.URL.RawQuery = target.RawQuery + req.URL.RawQuery req.URL.RawQuery = target.RawQuery + req.URL.RawQuery
@ -72,6 +72,8 @@ func ProxyHandlerRemote(target *url.URL, insecureSkipVerify bool) *httputil.Reve
} else { } else {
req.URL.Path = path.Join(target.Path, req.URL.Path) req.URL.Path = path.Join(target.Path, req.URL.Path)
} }
req.Host = target.Host
} }
p := &httputil.ReverseProxy{Director: director} p := &httputil.ReverseProxy{Director: director}