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"
|
"errors"
|
||||||
"github.com/graarh/golang-socketio/protocol"
|
"github.com/graarh/golang-socketio/protocol"
|
||||||
"github.com/graarh/golang-socketio/transport"
|
"github.com/graarh/golang-socketio/transport"
|
||||||
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -49,6 +50,7 @@ type Channel struct {
|
||||||
|
|
||||||
server *Server
|
server *Server
|
||||||
ip string
|
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 {
|
func outLoop(c *Channel, m *methods) error {
|
||||||
for {
|
for {
|
||||||
outBufferLen := len(c.out)
|
outBufferLen := len(c.out)
|
||||||
if outBufferLen >= queueBufferSize - 1 {
|
if outBufferLen >= queueBufferSize-1 {
|
||||||
return CloseChannel(c, m, ErrorSocketOverflood)
|
return CloseChannel(c, m, ErrorSocketOverflood)
|
||||||
} else if outBufferLen > int(queueBufferSize/2) {
|
} else if outBufferLen > int(queueBufferSize/2) {
|
||||||
overfloodedLock.Lock()
|
overfloodedLock.Lock()
|
||||||
|
|
16
server.go
16
server.go
|
@ -39,11 +39,18 @@ type Server struct {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get ip of socket client
|
Get ip of socket client
|
||||||
*/
|
*/
|
||||||
func (c *Channel) Ip() string {
|
func (c *Channel) Ip() string {
|
||||||
return c.ip
|
return c.ip
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get request header of this connection
|
||||||
|
*/
|
||||||
|
func (c *Channel) RequestHeader() http.Header {
|
||||||
|
return c.requestHeader
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get channel by it's sid
|
Get channel by it's sid
|
||||||
*/
|
*/
|
||||||
|
@ -279,7 +286,9 @@ func (s *Server) SendOpenSequence(c *Channel) {
|
||||||
/**
|
/**
|
||||||
Setup event loop for given connection
|
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()
|
interval, timeout := conn.PingParams()
|
||||||
hdr := Header{
|
hdr := Header{
|
||||||
Sid: generateNewId(remoteAddr),
|
Sid: generateNewId(remoteAddr),
|
||||||
|
@ -291,6 +300,7 @@ func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string) {
|
||||||
c := &Channel{}
|
c := &Channel{}
|
||||||
c.conn = conn
|
c.conn = conn
|
||||||
c.ip = remoteAddr
|
c.ip = remoteAddr
|
||||||
|
c.requestHeader = requestHeader
|
||||||
c.initChannel()
|
c.initChannel()
|
||||||
|
|
||||||
c.server = s
|
c.server = s
|
||||||
|
@ -313,7 +323,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.SetupEventLoop(conn, r.RemoteAddr)
|
s.SetupEventLoop(conn, r.RemoteAddr, r.Header)
|
||||||
s.tr.Serve(w, r)
|
s.tr.Serve(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue