Documentation
¶
Index ¶
- Constants
- Variables
- func FormatCloseMessage(closeCode int, text string) []byte
- func IsCloseError(err error, codes ...int) bool
- func IsUnexpectedCloseError(err error, expectedCodes ...int) bool
- func IsWebSocketUpgrade(c *fiber.Ctx) bool
- func JoinMessages(c *websocket.Conn, term string) io.Reader
- func NewWs(handler func(*fiber.Ctx, *Conn), config ...WsCfg) fiber.Handler
- type Config
- type Conn
- type WsCfg
Constants ¶
const ( CloseNormalClosure = 1000 CloseGoingAway = 1001 CloseProtocolError = 1002 CloseUnsupportedData = 1003 CloseNoStatusReceived = 1005 CloseAbnormalClosure = 1006 CloseInvalidFramePayloadData = 1007 ClosePolicyViolation = 1008 CloseMessageTooBig = 1009 CloseMandatoryExtension = 1010 CloseInternalServerErr = 1011 CloseServiceRestart = 1012 CloseTryAgainLater = 1013 CloseTLSHandshake = 1015 )
Close codes defined in RFC 6455, section 11.7.
const ( // TextMessage denotes a text data message. The text message payload is // interpreted as UTF-8 encoded text data. TextMessage = 1 // BinaryMessage denotes a binary data message. BinaryMessage = 2 // CloseMessage denotes a close control message. The optional message // payload contains a numeric code and text. Use the FormatCloseMessage // function to format a close message payload. CloseMessage = 8 // PingMessage denotes a ping control message. The optional message payload // is UTF-8 encoded text. PingMessage = 9 // PongMessage denotes a pong control message. The optional message payload // is UTF-8 encoded text. PongMessage = 10 )
The message types are defined in RFC 6455, section 11.8.
Variables ¶
Functions ¶
func FormatCloseMessage ¶
FormatCloseMessage formats closeCode and text as a WebSocket close message. An empty message is returned for code CloseNoStatusReceived.
func IsCloseError ¶
IsCloseError returns boolean indicating whether the error is a *CloseError with one of the specified codes.
func IsUnexpectedCloseError ¶
IsUnexpectedCloseError returns boolean indicating whether the error is a *CloseError with a code not in the list of expected codes.
func IsWebSocketUpgrade ¶
IsWebSocketUpgrade returns true if the client requested upgrade to the WebSocket protocol.
func JoinMessages ¶
JoinMessages concatenates received messages to create a single io.Reader. The string term is appended to each message. The returned reader does not support concurrent calls to the Read method.
Types ¶
type Config ¶
type Config struct {
Prefork bool `yaml:"-"`
ServerHeader string `yaml:"-"`
CaseSensitive bool `yaml:"-"`
Immutable bool `yaml:"-"`
UnescapePath bool `yaml:"-"`
ProxyHeader string `yaml:"-"`
GETOnly bool `yaml:"-"`
DisableKeepalive bool `yaml:"-"`
DisableDefaultDate bool `yaml:"-"`
DisableDefaultContentType bool `yaml:"-"`
ErrorHandler fiber.ErrorHandler `yaml:"-" json:"-"`
BodyLimit int `yaml:"-"`
Concurrency int `yaml:"-"`
// StreamRequestBody enables request body streaming,
// and calls the handler sooner when given body is
// larger then the current limit.
StreamRequestBody bool `yaml:"stream_request_body"`
// Will not pre parse Multipart Form data if set to true.
//
// This option is useful for servers that desire to treat
// multipart form data as a binary blob, or choose when to parse the data.
//
// Server pre parses multipart form data by default.
DisablePreParseMultipartForm bool `yaml:"disable_pre_parse_multipart_form"`
// Aggressively reduces memory usage at the cost of higher CPU usage
// if set to true.
//
// Try enabling this option only if the server consumes too much memory
// serving mostly idle keep-alive connections. This may reduce memory
// usage by more than 50%.
//
// Default: false
ReduceMemoryUsage bool `yaml:"reduce_memory_usage"`
// If set to true, c.IP() and c.IPs() will validate IP addresses before returning them.
// Also, c.IP() will return only the first valid IP rather than just the raw header
// WARNING: this has a performance cost associated with it.
//
// Default: false
EnableIPValidation bool `yaml:"enable_ip_validation"`
// If set to true, will print all routes with their method, path and handler.
// Default: false
EnablePrintRoutes bool `yaml:"enable_print_routes"`
// EnableSplittingOnParsers splits the query/body/header parameters by comma when it's true.
// For example, you can use it to parse multiple values from a query parameter like this:
// /api?foo=bar,baz == foo[]=bar&foo[]=baz
//
// Optional. Default: false
EnableSplittingOnParsers bool `yaml:"enable_splitting_on_parsers"`
ETag bool `yaml:"etag"`
ReadTimeout time.Duration `yaml:"read_timeout"`
WriteTimeout time.Duration `yaml:"write_timeout"`
IdleTimeout time.Duration `yaml:"idle_timeout"`
ReadBufferSize int `yaml:"read_buffer_size"`
WriteBufferSize int `yaml:"write_buffer_size"`
CompressedFileSuffix string `yaml:"compressed_file_suffix"`
DisableHeaderNormalizing bool `yaml:"disable_header_normalizing"`
DisableStartupMessage bool `yaml:"disable_startup_message"`
}
type Conn ¶
Conn https://godoc.org/github.com/gorilla/websocket#pkg-index
func (*Conn) Cookies ¶
Cookies is used for getting a cookie value by key Defaults to empty string "" if the cookie doesn't exist. If a default value is given, it will return that value if the cookie doesn't exist.
func (*Conn) Locals ¶
Locals makes it possible to pass interface{} values under string keys scoped to the request and therefore available to all following routes that match the request.
type WsCfg ¶
type WsCfg struct {
// Filter defines a function to skip middleware.
// Optional. Default: nil
Filter func(*fiber.Ctx) bool
// HandshakeTimeout specifies the duration for the handshake to complete.
HandshakeTimeout time.Duration
// Subprotocols specifies the client's requested subprotocols.
Subprotocols []string
// Allowed Origin's based on the Origin header, this validate the request origin to
// prevent cross-site request forgery. Everything is allowed if left empty.
Origins []string
// ReadBufferSize and WriteBufferSize specify I/O buffer sizes in bytes. If a buffer
// size is zero, then a useful default size is used. The I/O buffer sizes
// do not limit the size of the messages that can be sent or received.
ReadBufferSize, WriteBufferSize int
// EnableCompression specifies if the client should attempt to negotiate
// per message compression (RFC 7692). Setting this value to true does not
// guarantee that compression will be supported. Currently only "no context
// takeover" modes are supported.
EnableCompression bool
}
WsCfg ...