From 61eb0294e68612291d89d4bd319910974741eba4 Mon Sep 17 00:00:00 2001 From: Gennadii Kovalev Date: Tue, 16 Aug 2016 02:31:06 +0200 Subject: [PATCH] server. store connection header. (for X-Forwarded-For, and so on) --- loop.go | 8 +++++--- server.go | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/loop.go b/loop.go index 19c3772..138c2f9 100644 --- a/loop.go +++ b/loop.go @@ -5,6 +5,7 @@ import ( "errors" "github.com/graarh/golang-socketio/protocol" "github.com/graarh/golang-socketio/transport" + "net/http" "sync" "time" ) @@ -47,8 +48,9 @@ type Channel struct { ack ackProcessor - server *Server - ip string + server *Server + ip string + requestHeader http.Header } /** @@ -150,7 +152,7 @@ outgoing messages loop, sends messages from channel to socket func outLoop(c *Channel, m *methods) error { for { outBufferLen := len(c.out) - if outBufferLen >= queueBufferSize - 1 { + if outBufferLen >= queueBufferSize-1 { return CloseChannel(c, m, ErrorSocketOverflood) } else if outBufferLen > int(queueBufferSize/2) { overfloodedLock.Lock() diff --git a/server.go b/server.go index 055963a..97ffd7d 100644 --- a/server.go +++ b/server.go @@ -39,11 +39,18 @@ type Server struct { /** Get ip of socket client - */ +*/ func (c *Channel) Ip() string { return c.ip } +/** +Get request header of this connection +*/ +func (c *Channel) RequestHeader() http.Header { + return c.requestHeader +} + /** Get channel by it's sid */ @@ -279,7 +286,9 @@ func (s *Server) SendOpenSequence(c *Channel) { /** Setup event loop for given connection */ -func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string) { +func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string, + requestHeader http.Header) { + interval, timeout := conn.PingParams() hdr := Header{ Sid: generateNewId(remoteAddr), @@ -291,6 +300,7 @@ func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string) { c := &Channel{} c.conn = conn c.ip = remoteAddr + c.requestHeader = requestHeader c.initChannel() c.server = s @@ -313,7 +323,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - s.SetupEventLoop(conn, r.RemoteAddr) + s.SetupEventLoop(conn, r.RemoteAddr, r.Header) s.tr.Serve(w, r) }