[tor-commits] [snowflake/master] Initialize the global upgrader.CheckOrigin statically.

dcf at torproject.org dcf at torproject.org
Fri Jan 31 07:07:10 UTC 2020


commit 5b01df903085fbba96e52277e598c395bce27d88
Author: David Fifield <david at bamsoftware.com>
Date:   Tue Jan 28 00:09:38 2020 -0700

    Initialize the global upgrader.CheckOrigin statically.
    
    Only once, not again on every call to initServer.
---
 server/server.go | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/server/server.go b/server/server.go
index 9023252..acb260a 100644
--- a/server/server.go
+++ b/server/server.go
@@ -94,7 +94,9 @@ func clientAddr(clientIPParam string) string {
 	return (&net.TCPAddr{IP: clientIP, Port: 1, Zone: ""}).String()
 }
 
-var upgrader = websocket.Upgrader{}
+var upgrader = websocket.Upgrader{
+	CheckOrigin: func(r *http.Request) bool { return true },
+}
 
 type HTTPHandler struct{}
 
@@ -139,8 +141,6 @@ func initServer(addr *net.TCPAddr,
 		return nil, fmt.Errorf("cannot listen on port %d; configure a port using ServerTransportListenAddr", addr.Port)
 	}
 
-	upgrader.CheckOrigin = func(r *http.Request) bool { return true }
-
 	var handler HTTPHandler
 	server := &http.Server{
 		Addr:        addr.String(),





More information about the tor-commits mailing list