diff --git a/client.go b/client.go index deded6c..c9f8fba 100644 --- a/client.go +++ b/client.go @@ -1,14 +1,17 @@ package gosocketio import ( - "github.com/graarh/golang-socketio/transport" + "fmt" + "github.com/n0needt0/golang-socketio/transport" + "net/url" "strconv" + "strings" ) const ( - webSocketProtocol = "ws://" + webSocketProtocol = "ws://" webSocketSecureProtocol = "wss://" - socketioUrl = "/socket.io/?EIO=3&transport=websocket" + socketioUrl = "/socket.io/?EIO=3&transport=websocket" ) /** @@ -21,15 +24,30 @@ type Client struct { /** Get ws/wss url by host and port - */ -func GetUrl(host string, port int, secure bool) string { +*/ +func GetUrl(host string, port int, params []string, secure bool) string { var prefix string if secure { prefix = webSocketSecureProtocol } else { prefix = webSocketProtocol } - return prefix + host + ":" + strconv.Itoa(port) + socketioUrl + + _url, err := url.Parse(prefix + host + ":" + strconv.Itoa(port) + socketioUrl) + if err != nil { + fmt.Println("We unable to parse given url: ", _url) + } + + if len(params) > 0 { + _uval := _url.Query() + for _, element := range params { + s := strings.Split(element, "=") + _uval.Add(s[0], s[1]) + } + _url.RawQuery = _uval.Encode() + } + + return _url.String() } /** diff --git a/handler.go b/handler.go index 78c3636..07ccf48 100644 --- a/handler.go +++ b/handler.go @@ -2,9 +2,9 @@ package gosocketio import ( "encoding/json" - "github.com/graarh/golang-socketio/protocol" - "sync" + "github.com/n0needt0/golang-socketio/protocol" "reflect" + "sync" ) const ( diff --git a/loop.go b/loop.go index 5e73c5b..a2da23e 100644 --- a/loop.go +++ b/loop.go @@ -3,8 +3,8 @@ package gosocketio import ( "encoding/json" "errors" - "github.com/graarh/golang-socketio/protocol" - "github.com/graarh/golang-socketio/transport" + "github.com/n0needt0/golang-socketio/protocol" + "github.com/n0needt0/golang-socketio/transport" "net/http" "sync" "time" @@ -48,9 +48,10 @@ type Channel struct { ack ackProcessor - server *Server - ip string - requestHeader http.Header + server *Server + ip string + requestHeader http.Header + requestRequest http.Request } /** diff --git a/send.go b/send.go index 07e8130..db8d777 100644 --- a/send.go +++ b/send.go @@ -3,7 +3,7 @@ package gosocketio import ( "encoding/json" "errors" - "github.com/graarh/golang-socketio/protocol" + "github.com/n0needt0/golang-socketio/protocol" "log" "time" ) diff --git a/server.go b/server.go index 7583633..6341bbf 100644 --- a/server.go +++ b/server.go @@ -7,8 +7,8 @@ import ( "encoding/json" "errors" "fmt" - "github.com/graarh/golang-socketio/protocol" - "github.com/graarh/golang-socketio/transport" + "github.com/n0needt0/golang-socketio/protocol" + "github.com/n0needt0/golang-socketio/transport" "math/rand" "net/http" "sync" @@ -43,7 +43,7 @@ type Server struct { /** Close current channel - */ +*/ func (c *Channel) Close() { if c.server != nil { closeChannel(c, &c.server.methods) @@ -68,6 +68,13 @@ func (c *Channel) RequestHeader() http.Header { return c.requestHeader } +/** +Get request uri of this connection +*/ +func (c *Channel) GetRequest() http.Request { + return c.requestRequest +} + /** Get channel by it's sid */ @@ -304,7 +311,7 @@ func (s *Server) SendOpenSequence(c *Channel) { Setup event loop for given connection */ func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string, - requestHeader http.Header) { + requestHeader http.Header, requestRequest http.Request) { interval, timeout := conn.PingParams() hdr := Header{ @@ -318,6 +325,7 @@ func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string, c.conn = conn c.ip = remoteAddr c.requestHeader = requestHeader + c.requestRequest = requestRequest c.initChannel() c.server = s @@ -340,7 +348,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - s.SetupEventLoop(conn, r.RemoteAddr, r.Header) + s.SetupEventLoop(conn, r.RemoteAddr, r.Header, *r) s.tr.Serve(w, r) }