Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to receive full initial http request #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
@@ -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"
)

/**
Expand All @@ -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()
}

/**
Expand Down
4 changes: 2 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
11 changes: 6 additions & 5 deletions loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

/**
Expand Down
2 changes: 1 addition & 1 deletion send.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gosocketio
import (
"encoding/json"
"errors"
"github.com/graarh/golang-socketio/protocol"
"github.com/n0needt0/golang-socketio/protocol"
"log"
"time"
)
Expand Down
18 changes: 13 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -43,7 +43,7 @@ type Server struct {

/**
Close current channel
*/
*/
func (c *Channel) Close() {
if c.server != nil {
closeChannel(c, &c.server.methods)
Expand All @@ -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
*/
Expand Down Expand Up @@ -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{
Expand All @@ -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
Expand All @@ -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)
}

Expand Down