Skip to content

Commit

Permalink
use X-Real-Ip if presented
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Feb 25, 2024
1 parent b055882 commit cc915be
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ func (s *Server) doEvent(ctx context.Context, ws *WebSocket, request []json.RawM
if advancedDeleter != nil {
advancedDeleter.AfterDelete(tag[1], evt.PubKey)
}

}
}

ws.WriteJSON(nostr.NoticeEnvelope("OK"))
return ""
}

Expand Down Expand Up @@ -348,7 +351,11 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
ticker := time.NewTicker(pingPeriod)
stop := make(chan struct{})

s.Log.Infof("connected from %s", conn.RemoteAddr().String())
ip := conn.RemoteAddr().String()
if realIP := r.Header.Get("X-Real-Ip"); realIP != "" {
ip = realIP
}
s.Log.Infof("connected from %s", ip)

ws := challenge(conn)

Expand All @@ -372,7 +379,7 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
removeListener(ws)
}
s.clientsMu.Unlock()
s.Log.Infof("disconnected from %s", conn.RemoteAddr().String())
s.Log.Infof("disconnected from %s", ip)

ctx.Done()
}()
Expand Down Expand Up @@ -438,7 +445,7 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
s.Log.Errorf("error writing ping: %v; closing websocket", err)
return
}
s.Log.Infof("pinging for %s", conn.RemoteAddr().String())
s.Log.Infof("pinging for %s", ip)
case <-stop:
return
}
Expand Down

0 comments on commit cc915be

Please sign in to comment.