ソースを参照

Fixed UserAgent resp bug

Toby Chui 11 ヶ月 前
コミット
b5b32e5f80
2 ファイル変更6 行追加4 行削除
  1. 6 0
      mod/dynamicproxy/dpcore/dpcore.go
  2. 0 4
      mod/reverseproxy/reverse.go

+ 6 - 0
mod/dynamicproxy/dpcore/dpcore.go

@@ -375,6 +375,12 @@ func (p *ReverseProxy) ProxyHTTP(rw http.ResponseWriter, req *http.Request, rrr
 	// Remove hop-by-hop headers listed in the "Connection" header of the response, Remove hop-by-hop headers.
 	removeHeaders(res.Header, rrr.NoCache)
 
+	//Remove the User-Agent header if exists
+	if _, ok := res.Header["User-Agent"]; ok {
+		//Server to client request should not contains a User-Agent header
+		res.Header.Del("User-Agent")
+	}
+
 	if p.ModifyResponse != nil {
 		if err := p.ModifyResponse(res); err != nil {
 			if p.Verbal {

+ 0 - 4
mod/reverseproxy/reverse.go

@@ -85,10 +85,6 @@ func NewReverseProxy(target *url.URL) *ReverseProxy {
 		} else {
 			req.URL.RawQuery = targetQuery + "&" + req.URL.RawQuery
 		}
-
-		if _, ok := req.Header["User-Agent"]; !ok {
-			req.Header.Set("User-Agent", "")
-		}
 	}
 
 	return &ReverseProxy{Director: director, Verbal: false}