Skip to content

Commit 61eb029

Browse files
author
Gennadii Kovalev
committed
server. store connection header. (for X-Forwarded-For, and so on)
1 parent 7b8d3ac commit 61eb029

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

loop.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"github.com/graarh/golang-socketio/protocol"
77
"github.com/graarh/golang-socketio/transport"
8+
"net/http"
89
"sync"
910
"time"
1011
)
@@ -47,8 +48,9 @@ type Channel struct {
4748

4849
ack ackProcessor
4950

50-
server *Server
51-
ip string
51+
server *Server
52+
ip string
53+
requestHeader http.Header
5254
}
5355

5456
/**
@@ -150,7 +152,7 @@ outgoing messages loop, sends messages from channel to socket
150152
func outLoop(c *Channel, m *methods) error {
151153
for {
152154
outBufferLen := len(c.out)
153-
if outBufferLen >= queueBufferSize - 1 {
155+
if outBufferLen >= queueBufferSize-1 {
154156
return CloseChannel(c, m, ErrorSocketOverflood)
155157
} else if outBufferLen > int(queueBufferSize/2) {
156158
overfloodedLock.Lock()

server.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,18 @@ type Server struct {
3939

4040
/**
4141
Get ip of socket client
42-
*/
42+
*/
4343
func (c *Channel) Ip() string {
4444
return c.ip
4545
}
4646

47+
/**
48+
Get request header of this connection
49+
*/
50+
func (c *Channel) RequestHeader() http.Header {
51+
return c.requestHeader
52+
}
53+
4754
/**
4855
Get channel by it's sid
4956
*/
@@ -279,7 +286,9 @@ func (s *Server) SendOpenSequence(c *Channel) {
279286
/**
280287
Setup event loop for given connection
281288
*/
282-
func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string) {
289+
func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string,
290+
requestHeader http.Header) {
291+
283292
interval, timeout := conn.PingParams()
284293
hdr := Header{
285294
Sid: generateNewId(remoteAddr),
@@ -291,6 +300,7 @@ func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string) {
291300
c := &Channel{}
292301
c.conn = conn
293302
c.ip = remoteAddr
303+
c.requestHeader = requestHeader
294304
c.initChannel()
295305

296306
c.server = s
@@ -313,7 +323,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
313323
return
314324
}
315325

316-
s.SetupEventLoop(conn, r.RemoteAddr)
326+
s.SetupEventLoop(conn, r.RemoteAddr, r.Header)
317327
s.tr.Serve(w, r)
318328
}
319329

0 commit comments

Comments
 (0)