server. store connection header. (for X-Forwarded-For, and so on)
This commit is contained in:
parent
7b8d3aca48
commit
61eb0294e6
2
loop.go
2
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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
14
server.go
14
server.go
|
@ -44,6 +44,13 @@ 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