diff --git a/client/socket_handler.go b/client/socket_handler.go index 76a6131..7195c63 100644 --- a/client/socket_handler.go +++ b/client/socket_handler.go @@ -1,6 +1,8 @@ package client import ( + "crypto/tls" + "net" "net/http" "net/url" "time" @@ -12,14 +14,16 @@ type SocketHandler interface { SocketContext(parent cuc.Context) SocketContext GetURL() *url.URL + GetRequestCookie() http.CookieJar GetRequestHeader() http.Header - - GetMaxMessageSize() int64 - GetWriteTimeout() time.Duration - GetReadTimeout() time.Duration - GetPongTimeout() time.Duration - GetPingTimeout() time.Duration - GetPingPeriod() time.Duration + GetSubProtocols() []string + EnableCompression() bool + UseProxy(req *http.Request) (*url.URL, error) + GetHandshakeTimeout() time.Duration + Dial(network, addr string) (net.Conn, error) + GetTLSConfig() *tls.Config + GetReadBufferSize() int + GetWriteBufferSize() int // Validate is check handler value // If you override ths method, must call diff --git a/client/socket_handlers.go b/client/socket_handlers.go index 2692986..64fcc86 100644 --- a/client/socket_handlers.go +++ b/client/socket_handlers.go @@ -1,66 +1,75 @@ package client import ( + "crypto/tls" + "net" + "net/http" + "net/url" "time" + + cuc "git.loafle.net/commons_go/util/context" ) type SocketHandlers struct { - // MaxMessageSize is the maximum size for a message read from the peer. If a - // message exceeds the limit, the connection sends a close frame to the peer - // and returns ErrReadLimit to the application. - MaxMessageSize int64 - // WriteTimeout is the write deadline on the underlying network - // connection. After a write has timed out, the websocket state is corrupt and - // all future writes will return an error. A zero value for t means writes will - // not time out. - WriteTimeout time.Duration - // ReadTimeout is the read deadline on the underlying network connection. - // After a read has timed out, the websocket connection state is corrupt and - // all future reads will return an error. A zero value for t means reads will - // not time out. - ReadTimeout time.Duration - - PongTimeout time.Duration - PingTimeout time.Duration - PingPeriod time.Duration + URL *url.URL + RequestCookie http.CookieJar + RequestHeader http.Header + SubProtocols []string + EnableCompression bool + HandshakeTimeout time.Duration + TLSConfig *tls.Config + ReadBufferSize int + WriteBufferSize int } -func (sh *SocketHandlers) GetMaxMessageSize() int64 { - return sh.MaxMessageSize +func (sh *SocketHandlers) SocketContext(parent cuc.Context) SocketContext { + return newSocketContext(parent) } -func (sh *SocketHandlers) GetWriteTimeout() time.Duration { - return sh.WriteTimeout + +func (sh *SocketHandlers) GetURL() *url.URL { + return sh.URL } -func (sh *SocketHandlers) GetReadTimeout() time.Duration { - return sh.ReadTimeout + +func (sh *SocketHandlers) GetRequestCookie() http.CookieJar { + return sh.RequestCookie } -func (sh *SocketHandlers) GetPongTimeout() time.Duration { - return sh.PongTimeout + +func (sh *SocketHandlers) GetRequestHeader() http.Header { + return sh.RequestHeader } -func (sh *SocketHandlers) GetPingTimeout() time.Duration { - return sh.PingTimeout + +func (sh *SocketHandlers) GetSubProtocols() []string { + return sh.SubProtocols } -func (sh *SocketHandlers) GetPingPeriod() time.Duration { - return sh.PingPeriod + +func (sh *SocketHandlers) EnableCompression() bool { + return sh.EnableCompression +} + +func (sh *SocketHandlers) UseProxy(req *http.Request) (*url.URL, error) { + return nil, nil +} + +func (sh *SocketHandlers) GetHandshakeTimeout() time.Duration { + return sh.HandshakeTimeout +} + +func (sh *SocketHandlers) Dial(network, addr string) (net.Conn, error) { + return nil, nil +} + +func (sh *SocketHandlers) GetTLSConfig() *tls.Config { + return sh.TLSConfig +} + +func (sh *SocketHandlers) GetReadBufferSize() int { + return sh.ReadBufferSize +} + +func (sh *SocketHandlers) GetWriteBufferSize() int { + return sh.WriteBufferSize } func (sh *SocketHandlers) Validate() { - if sh.MaxMessageSize <= 0 { - sh.MaxMessageSize = DefaultMaxMessageSize - } - if sh.WriteTimeout <= 0 { - sh.WriteTimeout = DefaultWriteTimeout - } - if sh.ReadTimeout <= 0 { - sh.ReadTimeout = DefaultReadTimeout - } - if sh.PongTimeout <= 0 { - sh.PongTimeout = DefaultPongTimeout - } - if sh.PingTimeout <= 0 { - sh.PingTimeout = DefaultPingTimeout - } - if sh.PingPeriod <= 0 { - sh.PingPeriod = DefaultPingPeriod - } + }