Extract X-Forwarded-* headers for WebSocket connections

This commit is contained in:
Simon Ser 2020-06-29 18:27:43 +02:00
parent 90250f5be5
commit 2c172fa8ca
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -151,5 +151,11 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
s.Logger.Printf("failed to serve HTTP connection: %v", err) s.Logger.Printf("failed to serve HTTP connection: %v", err)
return return
} }
s.handle(newWebsocketIRCConn(conn), req.RemoteAddr) remoteAddr := req.RemoteAddr
forwardedHost := req.Header.Get("X-Forwarded-For")
forwardedPort := req.Header.Get("X-Forwarded-Port")
if forwardedHost != "" && forwardedPort != "" {
remoteAddr = net.JoinHostPort(forwardedHost, forwardedPort)
}
s.handle(newWebsocketIRCConn(conn), remoteAddr)
} }