Documentation
¶
Overview ¶
TODO 等重写http1.1 解析器, 再把这代码重写下
Index ¶
- Variables
- func GetNoPortExists() string
- func StringToBytes(s string) (b []byte)
- type CloseErrMsg
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) ReadJSONTimeout(v interface{}, t time.Duration) (op Opcode, err error)
- func (c *Conn) ReadMessage() (all []byte, op Opcode, err error)
- func (c *Conn) ReadTimeout(t time.Duration) (all []byte, op Opcode, err error)
- func (c *Conn) WriteCloseTimeout(sc StatusCode, t time.Duration) (err error)
- func (c *Conn) WriteJSONTimeout(op Opcode, v interface{}, t time.Duration) (err error)
- func (c *Conn) WriteMessage(op Opcode, data []byte) (err error)
- func (c *Conn) WriteTimeout(op Opcode, data []byte, t time.Duration) (err error)
- type ConnOption
- type DialOption
- type Opcode
- type Option
- type ServerOption
- type StatusCode
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrWrongStatusCode = errors.New("Wrong status code") ErrUpgradeFieldValue = errors.New("The value of the upgrade field is not 'websocket'") ErrConnectionFieldValue = errors.New("The value of the connection field is not 'upgrade'") ErrSecWebSocketAccept = errors.New("The value of Sec-WebSocketAaccept field is invalid") ErrHostCannotBeEmpty = errors.New("Host cannot be empty") ErrSecWebSocketKey = errors.New("The value of SEC websocket key field is wrong") ErrSecWebSocketVersion = errors.New("The value of SEC websocket version field is wrong, not 13") ErrHTTPProtocolNotSupported = errors.New("HTTP protocol not supported") ErrOnlyGETSupported = errors.New("error:Only get methods are supported") ErrMaxControlFrameSize = errors.New("error:max control frame size > 125") ErrRsv123 = errors.New("error:rsv1 or rsv2 or rsv3 has a value") ErrOpcode = errors.New("error:wrong opcode") ErrNOTBeFragmented = errors.New("error:since control message MUST NOT be fragmented") ErrFrameOpcode = errors.New("error:since all data frames after the initial data frame must have opcode 0.") ErrTextNotUTF8 = errors.New("error:text is not utf8 data") ErrClosePayloadTooSmall = errors.New("error:close payload too small") ErrCloseValue = errors.New("error:close value is wrong") //close值不对 ErrEmptyClose = errors.New("error:close value is empty") //close的值是空的 ErrWriteClosed = errors.New("write close") )
View Source
var ErrClose = "websocket"
View Source
var ErrFramePayloadLength = errors.New("error frame payload length")
View Source
var (
ErrNotFoundHijacker = errors.New("not found Hijacker")
)
Functions ¶
Types ¶
type CloseErrMsg ¶
type CloseErrMsg struct {
Code StatusCode
Msg string
}
func (CloseErrMsg) Error ¶
func (c CloseErrMsg) Error() string
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func Dial ¶
https://datatracker.ietf.org/doc/html/rfc6455#section-4.1 又是一顿if else, 咬文嚼字
func Upgrade ¶
func Upgrade(w http.ResponseWriter, r *http.Request, opts ...ServerOption) (c *Conn, err error)
func (*Conn) ReadJSONTimeout ¶ added in v0.0.5
从websocket读取json
func (*Conn) ReadTimeout ¶
func (*Conn) WriteCloseTimeout ¶ added in v0.0.4
func (c *Conn) WriteCloseTimeout(sc StatusCode, t time.Duration) (err error)
func (*Conn) WriteJSONTimeout ¶ added in v0.0.5
写入json至websocket连接
type ConnOption ¶
type ConnOption struct {
// contains filtered or unexported fields
}
type DialOption ¶
func (*DialOption) Dial ¶
func (d *DialOption) Dial() (c *Conn, err error)
type ServerOption ¶
type ServerOption interface {
// contains filtered or unexported methods
}
func WithServerDecompressAndCompress ¶ added in v0.0.3
func WithServerDecompressAndCompress() ServerOption
配置压缩和解压缩
func WithServerReplyPing ¶
func WithServerReplyPing() ServerOption
配置自动回应ping frame, 当收到ping, 回一个pong
type StatusCode ¶
type StatusCode int16
https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1 这里记录了各种状态码的含义
const ( // NormalClosure 正常关闭 NormalClosure StatusCode = 1000 // EndpointGoingAway 对端正在消失 EndpointGoingAway StatusCode = 1001 // ProtocolError 表示对端由于协议错误正在终止连接 ProtocolError StatusCode = 1002 // DataCannotAccept 收到一个不能接受的数据类型 DataCannotAccept StatusCode = 1003 // NotConsistentMessageType 表示对端正在终止连接, 消息类型不一致 NotConsistentMessageType StatusCode = 1007 // TerminatingConnection 表示对端正在终止连接, 没有好用的错误, 可以用这个错误码表示 TerminatingConnection StatusCode = 1008 // TooBigMessage 消息太大, 不能处理, 关闭连接 TooBigMessage StatusCode = 1009 // NoExtensions 只用于客户端, 服务端返回扩展消息 NoExtensions StatusCode = 1010 // ServerTerminating 服务端遇到意外情况, 中止请求 ServerTerminating StatusCode = 1011 )
func (StatusCode) String ¶
func (s StatusCode) String() string
Click to show internal directories.
Click to hide internal directories.