diff --git a/handler/proxy.go b/handler/proxy.go index dec0650..8832f4b 100644 --- a/handler/proxy.go +++ b/handler/proxy.go @@ -1,6 +1,7 @@ package handler import ( + "crypto/tls" "fmt" "net/http" "net/http/httputil" @@ -58,7 +59,12 @@ func (p *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // 返回值: // httputil.ReverseProxy实例 func makeProxy(upstream string, path *model.HttpPath, index int) *httputil.ReverseProxy { + l := gologger.GetLogger("Proxy") p := &httputil.ReverseProxy{} + p.Transport = &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } + directiveHandlers := []func(r *http.Request){} if len(path.Directives) > 0 { for _, directive := range path.Directives { @@ -76,10 +82,12 @@ func makeProxy(upstream string, path *model.HttpPath, index int) *httputil.Rever p.Director = func(req *http.Request) { for _, handler := range directiveHandlers { handler(req) + l.Info(fmt.Sprintf("proxy %s to %s", req.URL.String(), upstream)) } } p.ModifyResponse = func(resp *http.Response) error { + l.Info(fmt.Sprintf("proxy %s to %s, with status %d", resp.Request.URL.String(), upstream, resp.StatusCode)) hasSticky := false for _, cookie := range resp.Cookies() { if cookie.Name == "s" { diff --git a/handler/proxyupdater.go b/handler/proxyupdater.go index 47cd13f..cab1b8d 100644 --- a/handler/proxyupdater.go +++ b/handler/proxyupdater.go @@ -11,6 +11,19 @@ import ( type ProxyRequestUpdater func(arg ...string) func(r *http.Request) var ProxyRequestUpdateMap = map[string]ProxyRequestUpdater{ + "Host": func(arg ...string) func(r *http.Request) { + targetUrl := arg[0] + return func(r *http.Request) { + turl, _ := url.Parse(targetUrl) + r.Host = turl.Host + } + }, + "XForwardFor": func(arg ...string) func(r *http.Request) { + return func(r *http.Request) { + r.Header.Set("X-Forwarded-For", r.RemoteAddr) + + } + }, "HostSchemas": func(arg ...string) func(r *http.Request) { targetUrl := arg[0] return func(r *http.Request) { diff --git a/include/www.a.com.json b/include/www.a.com.json index 1117398..0a1c7f6 100644 --- a/include/www.a.com.json +++ b/include/www.a.com.json @@ -21,6 +21,15 @@ "path": "/", "root": "./example", "default": "index.html" + }, + { + "path":"/HPImageArchive.aspx", + "upstreams":["https://cn.bing.com"], + "directives":[ + "Proxy_HostSchemas $target", + "Proxy_Host $target", + "Proxy_XForwardFor" + ] } ] } \ No newline at end of file