internal

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MagicNumber     = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
	FrameHeaderSize = 14
)
View Source
const (
	ThresholdV1 = 125
	ThresholdV2 = math.MaxUint16
	ThresholdV3 = math.MaxUint64
)
View Source
const (
	Lv1 = 128
	Lv2 = 1024
	Lv3 = 4 * 1024
	Lv4 = 16 * 1024
	Lv5 = 64 * 1024
)

buffer level

Variables

View Source
var (
	ErrUnauthorized            = GwsError("unauthorized")
	ErrHandshake               = GwsError("connecting handshake error")
	ErrTextEncoding            = GwsError("text frame payload must be utf8 encoding")
	ErrUnexpectedContentLength = GwsError("unexpected content length")
	ErrConnClosed              = GwsError("connection closed")
	ErrGetMethodRequired       = GwsError("http method must be get")
	ErrAsyncIOCapFull          = GwsError("async io capacity is full")
	ErrSchema                  = GwsError("protocol not supported")
	ErrStatusCode              = GwsError("status code error")
)
View Source
var (
	SecWebSocketVersion    = Pair{"Sec-WebSocket-Version", "13"}
	SecWebSocketKey        = Pair{"Sec-WebSocket-Key", ""}
	SecWebSocketExtensions = Pair{"Sec-WebSocket-Extensions", "permessage-deflate; server_no_context_takeover; client_no_context_takeover"}
	Connection             = Pair{"Connection", "Upgrade"}
	Upgrade                = Pair{"Upgrade", "websocket"}
	SecWebSocketAccept     = Pair{"Sec-WebSocket-Accept", ""}
	SecWebSocketProtocol   = Pair{"Sec-WebSocket-Protocol", ""}
)
View Source
var (
	AlphabetNumeric = &RandomString{
		layout: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
		r:      rand.New(rand.NewSource(time.Now().UnixNano())),
		mu:     sync.Mutex{},
	}

	Numeric = &RandomString{
		layout: "0123456789",
		r:      rand.New(rand.NewSource(time.Now().UnixNano())),
		mu:     sync.Mutex{},
	}
)
View Source
var FlateTail = []byte{0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff}

Add four bytes as specified in RFC Add final block to squelch unexpected EOF error from flate reader.

Functions

func CheckIOError added in v1.4.5

func CheckIOError(expectN, realN int, err error) error

IO Utils ReadN WriteN CopyN

func ComputeAcceptKey

func ComputeAcceptKey(challengeKey string) string

func CopyN added in v1.2.12

func CopyN(dst io.Writer, src io.Reader, n int64) error

func Errors added in v1.3.5

func Errors(funcs ...func() error) error

func FnvNumber added in v1.5.1

func FnvNumber[T Integer](x T) uint64

func FnvString added in v1.5.1

func FnvString(s string) uint64

func HttpHeaderEqual added in v1.4.6

func HttpHeaderEqual(a, b string) bool

func InCollection added in v1.4.3

func InCollection(elem string, elems []string) bool

func IsNil added in v1.5.1

func IsNil(v interface{}) bool

func MaskByByte

func MaskByByte(content []byte, key []byte)

func MaskXOR added in v1.3.0

func MaskXOR(b []byte, key []byte)

func MethodExists added in v1.2.7

func MethodExists(in interface{}, method string) (reflect.Value, bool)

MethodExists if nil return false

func NewBufferWithCap added in v1.2.0

func NewBufferWithCap(n uint8) *bytes.Buffer

func NewMaskKey

func NewMaskKey() [4]byte

func ReadN added in v1.2.12

func ReadN(reader io.Reader, data []byte, n int) error

func SelectInt added in v1.4.6

func SelectInt[T Integer](ok bool, a, b T) T

func Split added in v1.4.3

func Split(s string, sep string) []string

Split 分割字符串(空值将会被过滤掉)

func StringToBytes added in v1.2.9

func StringToBytes(s string) []byte

func ToBinaryNumber added in v1.5.1

func ToBinaryNumber[T Integer](n T) T

func WriteN added in v1.2.12

func WriteN(writer io.Writer, content []byte, n int) error

Types

type BufferPool

type BufferPool struct {
	// contains filtered or unexported fields
}

func NewBufferPool

func NewBufferPool() *BufferPool

func (*BufferPool) Get

func (p *BufferPool) Get(n int) *bytes.Buffer

func (*BufferPool) Put

func (p *BufferPool) Put(b *bytes.Buffer, n int)

type Error added in v1.2.1

type Error struct {
	Err  error
	Code StatusCode
}

func NewError added in v1.2.1

func NewError(code StatusCode, err error) *Error

func (*Error) Error added in v1.2.1

func (c *Error) Error() string

type GwsError added in v1.2.16

type GwsError string

func (GwsError) Error added in v1.2.16

func (c GwsError) Error() string

type Integer added in v1.5.1

type Integer interface {
	int | int64 | int32 | uint | uint64 | uint32
}

type NetConn added in v1.2.13

type NetConn interface {
	NetConn() net.Conn
}

type Pair added in v1.3.5

type Pair struct {
	Key string
	Val string
}

type RandomString

type RandomString struct {
	// contains filtered or unexported fields
}

func (*RandomString) Generate

func (c *RandomString) Generate(n int) []byte

func (*RandomString) Intn added in v1.0.1

func (c *RandomString) Intn(n int) int

func (*RandomString) Uint32 added in v1.0.1

func (c *RandomString) Uint32() uint32

func (*RandomString) Uint64 added in v1.4.2

func (c *RandomString) Uint64() uint64

type ReadLener added in v1.2.9

type ReadLener interface {
	io.Reader
	Len() int
}

type StatusCode added in v1.2.0

type StatusCode uint16
const (
	// 正常关闭; 无论为何目的而创建, 该链接都已成功完成任务.
	CloseNormalClosure StatusCode = 1000

	// 终端离开, 可能因为服务端错误, 也可能因为浏览器正从打开连接的页面跳转离开.
	CloseGoingAway StatusCode = 1001

	// 由于协议错误而中断连接.
	CloseProtocolError StatusCode = 1002

	// 由于接收到不允许的数据类型而断开连接 (如仅接收文本数据的终端接收到了二进制数据).
	CloseUnsupported StatusCode = 1003

	// 保留. 表示没有收到预期的状态码.
	CloseNoStatusReceived StatusCode = 1005

	// 保留. 用于期望收到状态码时连接非正常关闭 (也就是说, 没有发送关闭帧).
	CloseAbnormalClosure StatusCode = 1006

	// 由于收到了格式不符的数据而断开连接 (如文本消息中包含了非 UTF-8 数据).
	CloseUnsupportedData StatusCode = 1007

	// 由于收到不符合约定的数据而断开连接. 这是一个通用状态码, 用于不适合使用 1003 和 1009 状态码的场景.
	ClosePolicyViolation StatusCode = 1008

	// 由于收到过大的数据帧而断开连接.
	CloseMessageTooLarge StatusCode = 1009

	// 客户端期望服务器商定一个或多个拓展, 但服务器没有处理, 因此客户端断开连接.
	CloseMissingExtension StatusCode = 1010

	// 客户端由于遇到没有预料的情况阻止其完成请求, 因此服务端断开连接.
	CloseInternalServerErr StatusCode = 1011

	// 服务器由于重启而断开连接. [Ref]
	CloseServiceRestart StatusCode = 1012

	// 服务器由于临时原因断开连接, 如服务器过载因此断开一部分客户端连接. [Ref]
	CloseTryAgainLater StatusCode = 1013

	// 保留. 表示连接由于无法完成 TLS 握手而关闭 (例如无法验证服务器证书).
	CloseTLSHandshake StatusCode = 1015
)

func (StatusCode) Bytes added in v1.2.0

func (c StatusCode) Bytes() []byte

func (StatusCode) Error added in v1.2.0

func (c StatusCode) Error() string

func (StatusCode) Uint16 added in v1.2.0

func (c StatusCode) Uint16() uint16

Jump to

Keyboard shortcuts

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