Browse Source

Prevent UA from being set to golang's default ones

Go automatically sets HTTP header `User-Agent' to `Go-http-client/1.1'
if it hasn't been set before, which in some cases breaks the
transparency of proxy.

Such behavior can be prevented by setting it to an empty string.
Valture 8 năm trước cách đây
mục cha
commit
973378d610
1 tập tin đã thay đổi với 5 bổ sung0 xóa
  1. 5 0
      proxy/http/server.go

+ 5 - 0
proxy/http/server.go

@@ -212,6 +212,11 @@ func StripHopByHopHeaders(header http.Header) {
 	for _, h := range strings.Split(connections, ",") {
 		header.Del(strings.TrimSpace(h))
 	}
+
+	// Prevent UA from being set to golang's default ones
+	if len(header.Get("User-Agent")) == 0 {
+		header.Set("User-Agent", "")
+	}
 }
 
 var errWaitAnother = newError("keep alive")