sockjsclient

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 17 Imported by: 0

README

go-sockjsclient

Fork of go-socksjsclient that adds functionality for query parameters and more or less disables underlying timeout from Socks

Documentation

Index

Constants

View Source
const (
	MessageTypeUnhandled = MessageType(iota)
	MessageTypeHeartbeat = MessageType(iota)
	MessageTypeData      = MessageType(iota)
	MessageTypeOpen      = MessageType(iota)
	MessageTypeClose     = MessageType(iota)
)

Sockjs message types (0th represents any unhandled, treated as error)

Variables

View Source
var (
	ErrClientNotConnected  = errors.New("sockjsclient: client not connected")
	ErrClientCannotConnect = errors.New("sockjsclient: client cannot connect")
	ErrClientCannotDecode  = errors.New("sockjsclient: client cannot decode")
)

Sockjs client error messages

View Source
var (
	ErrClosedConnection   = errors.New("sockjsclient: use of a closed connection")
	ErrClosedByRemote     = errors.New("sockjsclient: connection closed by remote")
	ErrClosingConnection  = errors.New("sockjsclient: error closing connection")
	ErrInvalidResponse    = errors.New("sockjsclient: invalid server response")
	ErrUnexpectedResponse = errors.New("sockjsclient: unexpected server response")
	ErrNoHeartbeat        = errors.New("sockjsclient: no heartbeat")
)

Sockjs client connection error messages

Functions

func IsNotConnected

func IsNotConnected(err error) bool

IsNotConnected will return if this is a client / conn not connected error

Types

type Client

type Client struct {
	// Address is the base server address to connection
	Address string

	// Query parameters will be added after /websocket part of socksjs connect uri
	Query map[string]string

	// ServerID is the server ID string to be used in generation of the transport address
	ServerID string

	// SessionID is the session ID string to be used in generation of the transport address
	SessionID string

	// Header defines any HTTP headers to provide on first connect
	Header http.Header

	// WSDialer provides configuration for dialing WS connections
	WSDialer *WSDialer

	// XHRDialer provides configuration for dialing XHR connections
	XHRDialer *XHRDialer

	// NoWebsocket indicates whether to prefer XHR connection over WS
	NoWebsocket bool
	// contains filtered or unexported fields
}

func (*Client) Close

func (c *Client) Close() error

Close will close an open sockjs connection

func (*Client) Conn

func (c *Client) Conn() Conn

Conn returns the underlying conn (nil if not connected)

func (*Client) Connect

func (c *Client) Connect() error

func (*Client) ConnectContext

func (c *Client) ConnectContext(ctx context.Context) error

func (*Client) IsWebsocket

func (c *Client) IsWebsocket() bool

IsWebsocket returns whether current connection is via websocket

func (*Client) ReadJSON

func (c *Client) ReadJSON(v interface{}) error

ReadJSON will read next message from the sockjs connection and attempt JSON decode into "v"

func (*Client) ReadMsg

func (c *Client) ReadMsg() ([]byte, error)

ReadMsg will read the next message from the sockjs connection

func (*Client) ServerInfo

func (c *Client) ServerInfo() ServerInfo

ServerInfo returns ServerInfo related to current conn (empty if not connected)

func (*Client) WriteJSON

func (c *Client) WriteJSON(v interface{}) error

WriteJSON will JSON encode "v" and send to the sockjs connection

func (*Client) WriteMsg

func (c *Client) WriteMsg(msg []byte) error

WriteMsg will write a message to the sockjs connection

type Conn

type Conn interface {
	// ReadMsg reads the next single data message from the sockjs connection
	ReadMsg() ([]byte, error)

	// WriteMsg writes a block of data messages to the sockjs connection
	WriteMsg(...[]byte) error

	// Close will close the sockjs connection
	Close() error

	// GetConnection returns the underlying gorilla websocket connection
	GetConnection() *websocket.Conn
}

Conn represents a sockjs client connection

type MessageType

type MessageType uint8

MessageType represents a sockjs message type

type ServerInfo

type ServerInfo struct {
	WebSocket    bool     `json:"websocket"`
	CookieNeeded bool     `json:"cookie_needed"`
	Origins      []string `json:"origins"`
	Entropy      int      `json:"entropy"`
}

ServerInfo representations an "/info" response from a sockjs server

func GetServerInfo

func GetServerInfo(addr string) (*ServerInfo, *url.URL, error)

GetServerInfo attempts to fetch sockjs ServerInfo for given address and parse server addr

type WSDialer

type WSDialer struct {
	// Dialer is the underlying websocket dialer used
	// by the produced websocket conn
	Dialer *websocket.Dialer
}

func (*WSDialer) Dial

func (d *WSDialer) Dial(addr, serverID, sessionID string, hdrs http.Header, query map[string]string) (Conn, *http.Response, error)

func (*WSDialer) DialContext

func (d *WSDialer) DialContext(ctx context.Context, addr, serverID, sessionID string, hdrs http.Header, query map[string]string) (Conn, *http.Response, error)

type XHRDialer

type XHRDialer struct {
	// HTTPClient is the underlying http.Client used by
	// the produced XHR conn
	HTTPClient *http.Client
}

func (*XHRDialer) Dial

func (d *XHRDialer) Dial(addr, serverID, sessionID string, hdrs http.Header) (Conn, *http.Response, error)

func (*XHRDialer) DialContext

func (d *XHRDialer) DialContext(ctx context.Context, addr, serverID, sessionID string, hdrs http.Header) (Conn, *http.Response, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL