Get real IP of webscoket connection
This commit is contained in:
parent
af0711dc12
commit
1482b51503
@ -118,6 +118,14 @@ func checkOrigin(r *http.Request) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getIP(r *http.Request) string {
|
||||||
|
ip := r.Header.Get("X-Real-Ip")
|
||||||
|
if ip != "" {
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
return r.RemoteAddr
|
||||||
|
}
|
||||||
|
|
||||||
// ServeHTTP sets up handler of websocket channel
|
// ServeHTTP sets up handler of websocket channel
|
||||||
func (s *WebsocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *WebsocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != "GET" {
|
if r.Method != "GET" {
|
||||||
@ -133,7 +141,7 @@ func (s *WebsocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
id: atomic.AddUint64(&connectionCounter, 1),
|
id: atomic.AddUint64(&connectionCounter, 1),
|
||||||
conn: conn,
|
conn: conn,
|
||||||
out: make(chan *websocketRes, outChannelSize),
|
out: make(chan *websocketRes, outChannelSize),
|
||||||
ip: r.RemoteAddr,
|
ip: getIP(r),
|
||||||
requestHeader: r.Header,
|
requestHeader: r.Header,
|
||||||
alive: true,
|
alive: true,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user