server. store connection header. (for X-Forwarded-For, and so on)
This commit is contained in:
parent
7b8d3aca48
commit
61eb0294e6
4
loop.go
4
loop.go
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"github.com/graarh/golang-socketio/protocol"
|
||||
"github.com/graarh/golang-socketio/transport"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
@ -49,6 +50,7 @@ type Channel struct {
|
|||
|
||||
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()
|
||||
|
|
16
server.go
16
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue