Documentation ¶
Index ¶
- Constants
- Variables
- func ReleaseFrame(fr *Frame)
- func Upgrade(handler RequestHandler) func(ctx *fasthttp.RequestCtx)
- type Code
- type Conn
- func (conn *Conn) Close() error
- func (conn *Conn) CloseString(b string) error
- func (conn *Conn) LocalAddr() net.Addr
- func (conn *Conn) NextFrame() (fr *Frame, err error)
- func (conn *Conn) ReadFrame(fr *Frame) (nn int, err error)
- func (conn *Conn) ReadMessage(b []byte) (Mode, []byte, error)
- func (conn *Conn) RemoteAddr() net.Addr
- func (conn *Conn) ReplyClose(fr *Frame) (err error)
- func (conn *Conn) Reset(c net.Conn)
- func (conn *Conn) SendCode(code Code, status StatusCode, b []byte) error
- func (conn *Conn) SendCodeString(code Code, status StatusCode, b string) error
- func (conn *Conn) SetDeadline(t time.Time) error
- func (conn *Conn) SetReadDeadline(t time.Time) error
- func (conn *Conn) SetWriteDeadline(t time.Time) error
- func (conn *Conn) Write(b []byte) (int, error)
- func (conn *Conn) WriteFrame(fr *Frame) (int, error)
- func (conn *Conn) WriteMessage(mode Mode, b []byte) (int, error)
- func (conn *Conn) WriteString(b string) (int, error)
- type Frame
- func (fr *Frame) Code() Code
- func (fr *Frame) HasRSV1() bool
- func (fr *Frame) HasRSV2() bool
- func (fr *Frame) HasRSV3() bool
- func (fr *Frame) IsClose() bool
- func (fr *Frame) IsContinuation() bool
- func (fr *Frame) IsFin() bool
- func (fr *Frame) IsMasked() bool
- func (fr *Frame) IsPing() bool
- func (fr *Frame) IsPong() bool
- func (fr *Frame) Len() (length uint64)
- func (fr *Frame) Mask()
- func (fr *Frame) MaskKey() []byte
- func (fr *Frame) Mode() (mode Mode)
- func (fr *Frame) Payload() []byte
- func (fr *Frame) PayloadSize() uint64
- func (fr *Frame) ReadFrom(rd io.Reader) (nn uint64, err error)
- func (fr *Frame) Reset()
- func (fr *Frame) SetBinary()
- func (fr *Frame) SetClose()
- func (fr *Frame) SetCode(code Code)
- func (fr *Frame) SetContinuation()
- func (fr *Frame) SetFin()
- func (fr *Frame) SetMask(b []byte)
- func (fr *Frame) SetPayload(b []byte)
- func (fr *Frame) SetPayloadSize(size uint64)
- func (fr *Frame) SetPing()
- func (fr *Frame) SetPong()
- func (fr *Frame) SetRSV1()
- func (fr *Frame) SetRSV2()
- func (fr *Frame) SetRSV3()
- func (fr *Frame) SetStatus(status StatusCode)
- func (fr *Frame) SetText()
- func (fr *Frame) Status() (status StatusCode)
- func (fr *Frame) Unmask()
- func (fr *Frame) UnsetMask()
- func (fr *Frame) Write(b []byte) (int, error)
- func (fr *Frame) WriteTo(wr io.Writer) (n uint64, err error)
- type Mode
- type RequestHandler
- type StatusCode
- type UpgradeHandler
- type Upgrader
Constants ¶
const ( StatusNone StatusCode = 1000 StatusGoAway = 1001 StatusProtocolError = 1002 StatusNotAcceptable = 1003 StatusReserved = 1004 StatusNotConsistent = 1007 StatusViolation = 1008 StatusTooBig = 1009 StatuseExtensionsNeeded = 1010 StatusUnexpected = 1011 )
Variables ¶
var (
EOF = io.EOF
)
var (
ErrCannotUpgrade = errors.New("cannot upgrade connection")
)
Functions ¶
func Upgrade ¶
func Upgrade(handler RequestHandler) func(ctx *fasthttp.RequestCtx)
Upgrade returns a RequestHandler for fasthttp resuming upgrading process.
Types ¶
type Conn ¶
type Conn struct { // Mode indicates Write default mode. Mode Mode // MaxPayloadSize prevents huge memory allocation. // // By default MaxPayloadSize is 4096. MaxPayloadSize uint64 // contains filtered or unexported fields }
Conn represents websocket connection handler.
This handler is compatible with io.Reader, io.ReaderFrom, io.Writer, io.WriterTo
func Client ¶
Client returns Conn using existing connection.
url must be complete URL format i.e. http://localhost:8080/ws
func ClientWithHeaders ¶
ClientWithHeaders returns a Conn using existing connection and sending personalized headers.
func Dial ¶
Dial performs establishes websocket connection as client.
url parameter must follow WebSocket url format i.e. ws://host:port/path
func DialWithHeaders ¶
DialWithHeaders establishes websocket connection as client sending personalized request.
func (*Conn) CloseString ¶
CloseString sends b as close reason and closes the descriptor.
When connection is handled by server the connection is closed automatically.
func (*Conn) NextFrame ¶
NextFrame reads next connection frame and returns if there were no error.
If NextFrame fr is not nil do not forget to ReleaseFrame(fr) This function responds automatically to PING and PONG messages.
func (*Conn) ReadFrame ¶
ReadFrame fills fr with the next connection frame.
This function responds automatically to PING and PONG messages.
func (*Conn) ReadMessage ¶
ReadMessage reads next message from conn and returns the mode, b and/or error.
b is used to avoid extra allocations and can be nil.
func (*Conn) RemoteAddr ¶
RemoteAddr returns peer remote address.
func (*Conn) ReplyClose ¶
ReplyClose is used to reply to CodeClose.
func (*Conn) SendCode ¶
func (conn *Conn) SendCode(code Code, status StatusCode, b []byte) error
SendCode writes code, status and message to conn.
status is used by CodeClose to report any close status (as HTTP responses). Can be 0. b can be nil.
func (*Conn) SendCodeString ¶
func (conn *Conn) SendCodeString(code Code, status StatusCode, b string) error
SendCodeString writes code, status and message to conn as SendCode does.
func (*Conn) SetDeadline ¶
SetDeadline calls net.Conn.SetDeadline
func (*Conn) SetReadDeadline ¶
SetReadDeadline calls net.Conn.SetReadDeadline
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline calls net.Conn.SetWriteDeadline
func (*Conn) WriteFrame ¶
WriteFrame writes fr to the connection endpoint.
func (*Conn) WriteMessage ¶
WriteMessage writes b to conn using mode.
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame is the unit used to transfer message between endpoints using websocket protocol.
Frame could not be used during message exchanging. This type can be used if you want low level access to websocket.
func (*Frame) IsContinuation ¶
func (*Frame) PayloadSize ¶
PayloadSize returns max payload size.
func (*Frame) SetContinuation ¶
func (fr *Frame) SetContinuation()
SetContinuation sets CodeContinuation in Code field.
func (*Frame) SetPayloadSize ¶
SetPayloadSize sets max payload size.
func (*Frame) SetStatus ¶
func (fr *Frame) SetStatus(status StatusCode)
SetStatus sets status code to the request.
Status code is usually used in Close request.
func (*Frame) Status ¶
func (fr *Frame) Status() (status StatusCode)
Status returns StatusCode from request payload.
type StatusCode ¶
type StatusCode uint16
type UpgradeHandler ¶
type UpgradeHandler func(*fasthttp.RequestCtx) bool
RequestHandler is the websocket handler.
type Upgrader ¶
type Upgrader struct { // UpgradeHandler allows user to handle RequestCtx when upgrading. // // If UpgradeHandler returns false the connection won't be upgraded and // the parsed ctx will be used as a response. UpgradeHandler UpgradeHandler // Handler is the request handler for ws connections. Handler RequestHandler // Protocols are the supported protocols. Protocols []string // Origin ... Origin string // Compress ... Compress bool }
Upgrader upgrades HTTP connection to a websocket connection if it's possible.
Upgrader executes Upgrader.Handler after successful websocket upgrading.
func (*Upgrader) Upgrade ¶
func (upgr *Upgrader) Upgrade(ctx *fasthttp.RequestCtx)
Upgrader upgrades HTTP to websocket connection if possible.
If client does not request any websocket connection this function will execute ctx.NotFound()
When connection is successfully stablished this function calls s.Handler.