Просмотр исходного кода

User agent selection - Code review cleanup
- Remove extra call to `UserAgentIfUnset` from meekConn
- Rename 'internalUserAgent' to 'selectedUserAgent'

Michael Goldberger 9 лет назад
Родитель
Сommit
c0397b7711
5 измененных файлов с 11 добавлено и 13 удалено
  1. 3 3
      psiphon/common/userAgentPicker.go
  2. 0 2
      psiphon/meekConn.go
  3. 1 1
      psiphon/notice.go
  4. 1 1
      psiphon/serverApi.go
  5. 6 6
      psiphon/tunnel.go

+ 3 - 3
psiphon/common/userAgentPicker.go

@@ -39,7 +39,7 @@ func PickUserAgent() string {
 }
 
 func UserAgentIfUnset(h http.Header) (http.Header, bool) {
-	internalUserAgent := false
+	selectedUserAgent := false
 	if _, ok := h["User-Agent"]; !ok {
 		if h == nil {
 			h = make(map[string][]string)
@@ -51,8 +51,8 @@ func UserAgentIfUnset(h http.Header) (http.Header, bool) {
 			h.Set("User-Agent", "")
 		}
 
-		internalUserAgent = true
+		selectedUserAgent = true
 	}
 
-	return h, internalUserAgent
+	return h, selectedUserAgent
 }

+ 0 - 2
psiphon/meekConn.go

@@ -584,8 +584,6 @@ func (meek *MeekConn) roundTrip(sendPayload []byte) (io.ReadCloser, error) {
 
 		request.Header.Set("Content-Type", "application/octet-stream")
 
-		meek.additionalHeaders, _ = common.UserAgentIfUnset(meek.additionalHeaders)
-
 		// Set additional headers to the HTTP request using the same method we use for adding
 		// custom headers to HTTP proxy requests
 		for name, value := range meek.additionalHeaders {

+ 1 - 1
psiphon/notice.go

@@ -352,7 +352,7 @@ func NoticeConnectedTunnelDialStats(ipAddress string, tunnelDialStats *TunnelDia
 		"meekSNIServerName", tunnelDialStats.MeekSNIServerName,
 		"meekHostHeader", tunnelDialStats.MeekHostHeader,
 		"meekTransformedHostName", tunnelDialStats.MeekTransformedHostName,
-		"internalUserAgent", tunnelDialStats.InternalUserAgent,
+		"selectedUserAgent", tunnelDialStats.SelectedUserAgent,
 		"userAgent", tunnelDialStats.UserAgent)
 }
 

+ 1 - 1
psiphon/serverApi.go

@@ -849,7 +849,7 @@ func (serverContext *ServerContext) getBaseParams() requestJSONObject {
 		}
 		params["meek_transformed_host_name"] = transformedHostName
 
-		if tunnel.dialStats.InternalUserAgent {
+		if tunnel.dialStats.SelectedUserAgent {
 			params["user_agent"] = tunnel.dialStats.UserAgent
 		}
 	}

+ 6 - 6
psiphon/tunnel.go

@@ -103,7 +103,7 @@ type TunnelDialStats struct {
 	MeekSNIServerName              string
 	MeekHostHeader                 string
 	MeekTransformedHostName        bool
-	InternalUserAgent              bool
+	SelectedUserAgent              bool
 	UserAgent                      string
 }
 
@@ -623,8 +623,8 @@ func dialSsh(
 		resolvedIPAddress.Store(IPAddress)
 	}
 
-	var internalUserAgent bool
-	config.UpstreamProxyCustomHeaders, internalUserAgent = common.UserAgentIfUnset(config.UpstreamProxyCustomHeaders)
+	var selectedUserAgent bool
+	config.UpstreamProxyCustomHeaders, selectedUserAgent = common.UserAgentIfUnset(config.UpstreamProxyCustomHeaders)
 
 	// Create the base transport: meek or direct connection
 	dialConfig := &DialConfig{
@@ -759,8 +759,8 @@ func dialSsh(
 	if dialConfig.UpstreamProxyUrl != "" || meekConfig != nil {
 		dialStats = &TunnelDialStats{}
 
-		if internalUserAgent {
-			dialStats.InternalUserAgent = true
+		if selectedUserAgent {
+			dialStats.SelectedUserAgent = true
 			dialStats.UserAgent = dialConfig.UpstreamProxyCustomHeaders.Get("User-Agent")
 		}
 
@@ -774,7 +774,7 @@ func dialSsh(
 
 			dialStats.UpstreamProxyCustomHeaderNames = make([]string, 0)
 			for name, _ := range dialConfig.UpstreamProxyCustomHeaders {
-				if internalUserAgent && name == "User-Agent" {
+				if selectedUserAgent && name == "User-Agent" {
 					continue
 				}
 				dialStats.UpstreamProxyCustomHeaderNames = append(dialStats.UpstreamProxyCustomHeaderNames, name)