Versions in this module Expand all Collapse all v1 v1.3.2 Dec 25, 2023 Changes in this version + const DefaultClientReadBufferSize + const DefaultClientWriteBufferSize + const DefaultServerReadBufferSize + const DefaultServerWriteBufferSize + const MaxControlFramePayloadSize + const MaxHeaderSize + const MinHeaderSize + var CompiledClose = MustCompileFrame(NewCloseFrame(nil)) + var CompiledCloseGoingAway = MustCompileFrame(closeFrameGoingAway) + var CompiledCloseInternalServerError = MustCompileFrame(closeFrameInternalServerError) + var CompiledCloseInvalidFramePayloadData = MustCompileFrame(closeFrameInvalidFramePayloadData) + var CompiledCloseMandatoryExt = MustCompileFrame(closeFrameMandatoryExt) + var CompiledCloseMessageTooBig = MustCompileFrame(closeFrameMessageTooBig) + var CompiledCloseNoMeaningYet = MustCompileFrame(closeFrameNoMeaningYet) + var CompiledCloseNormalClosure = MustCompileFrame(closeFrameNormalClosure) + var CompiledClosePolicyViolation = MustCompileFrame(closeFramePolicyViolation) + var CompiledCloseProtocolError = MustCompileFrame(closeFrameProtocolError) + var CompiledCloseTLSHandshake = MustCompileFrame(closeFrameTLSHandshake) + var CompiledCloseUnsupportedData = MustCompileFrame(closeFrameUnsupportedData) + var CompiledPing = MustCompileFrame(NewPingFrame(nil)) + var CompiledPong = MustCompileFrame(NewPongFrame(nil)) + var ErrHandshakeBadConnection = RejectConnectionError(RejectionStatus(http.StatusBadRequest), ...) + var ErrHandshakeBadExtensions = fmt.Errorf("unexpected extensions in %q header", headerSecProtocol) + var ErrHandshakeBadHost = RejectConnectionError(RejectionStatus(http.StatusBadRequest), ...) + var ErrHandshakeBadMethod = RejectConnectionError(RejectionStatus(http.StatusMethodNotAllowed), ...) + var ErrHandshakeBadProtocol = RejectConnectionError(RejectionStatus(http.StatusHTTPVersionNotSupported), ...) + var ErrHandshakeBadSecAccept = RejectConnectionError(RejectionStatus(http.StatusBadRequest), ...) + var ErrHandshakeBadSecKey = RejectConnectionError(RejectionStatus(http.StatusBadRequest), ...) + var ErrHandshakeBadSecVersion = RejectConnectionError(RejectionStatus(http.StatusBadRequest), ...) + var ErrHandshakeBadStatus = fmt.Errorf("unexpected http status") + var ErrHandshakeBadSubProtocol = fmt.Errorf("unexpected protocol in %q header", headerSecProtocol) + var ErrHandshakeBadUpgrade = RejectConnectionError(RejectionStatus(http.StatusBadRequest), ...) + var ErrHandshakeUpgradeRequired = RejectConnectionError(RejectionStatus(http.StatusUpgradeRequired), ...) + var ErrHeaderLengthMSB = fmt.Errorf("header error: the most significant bit must be 0") + var ErrHeaderLengthUnexpected = fmt.Errorf("header error: unexpected payload length bits") + var ErrMalformedRequest = RejectConnectionError(RejectionStatus(http.StatusBadRequest), ...) + var ErrMalformedResponse = fmt.Errorf("malformed HTTP response") + var ErrNotHijacker = RejectConnectionError(RejectionStatus(http.StatusInternalServerError), ...) + var ErrProtocolContinuationExpected = ProtocolError("unexpected non-continuation data frame") + var ErrProtocolContinuationUnexpected = ProtocolError("unexpected continuation data frame") + var ErrProtocolControlNotFinal = ProtocolError("control frame is not final") + var ErrProtocolControlPayloadOverflow = ProtocolError("control frame payload limit exceeded") + var ErrProtocolInvalidUTF8 = ProtocolError("invalid utf8 sequence in close reason") + var ErrProtocolMaskRequired = ProtocolError("frames from client to server must be masked") + var ErrProtocolMaskUnexpected = ProtocolError("frames from server to client must be not masked") + var ErrProtocolNonZeroRsv = ProtocolError("non-zero rsv bits with no extension negotiated") + var ErrProtocolOpCodeReserved = ProtocolError("use of reserved op code") + var ErrProtocolStatusCodeApplicationLevel = ProtocolError("status code is only application level") + var ErrProtocolStatusCodeNoMeaning = ProtocolError("status code has no meaning yet") + var ErrProtocolStatusCodeNotInUse = ProtocolError("status code is not in use") + var ErrProtocolStatusCodeUnknown = ProtocolError("status code is not defined in spec") + var HostByte = []byte("Host") + var StatusRangeApplication = StatusCodeRange + var StatusRangeNotInUse = StatusCodeRange + var StatusRangePrivate = StatusCodeRange + var StatusRangeProtocol = StatusCodeRange + func CheckCloseFrameData(code StatusCode, reason string) error + func CheckHeader(h Header, s State) error + func Cipher(payload []byte, mask [4]byte, offset int) + func CompileFrame(f Frame) (bts []byte, err error) + func HeaderSize(h Header) (n int) + func MustCompileFrame(f Frame) []byte + func MustWriteFrame(w io.Writer, f Frame) + func NewCloseFrameBody(code StatusCode, reason string) []byte + func NewMask() (ret [4]byte) + func PutCloseFrameBody(p []byte, code StatusCode, reason string) + func PutReader(br *bufio.Reader) + func RejectConnectionError(options ...RejectOption) error + func Rsv(r1, r2, r3 bool) (rsv byte) + func RsvBits(rsv byte) (r1, r2, r3 bool) + func SelectEqual(v string) func(string) bool + func SelectFromSlice(accept []string) func(string) bool + func WriteFrame(w io.Writer, f Frame) error + func WriteHeader(w io.Writer, h Header) error + type ConnectionRejectedError struct + func (r *ConnectionRejectedError) Error() string + func (r *ConnectionRejectedError) StatusCode() int + type Dialer struct + Extensions []httphead.Option + Header HandshakeHeader + NetDial func(ctx context.Context, network, addr string) (net.Conn, error) + OnHeader func(key, value []byte) (err error) + OnStatusError func(status int, reason []byte, resp io.Reader) + Protocols []string + ReadBufferSize int + TLSClient func(conn net.Conn, hostname string) net.Conn + TLSConfig *tls.Config + Timeout time.Duration + WrapConn func(conn net.Conn) net.Conn + WriteBufferSize int + var DefaultDialer Dialer + func (d Dialer) Dial(ctx context.Context, urlstr string) (conn net.Conn, br *bufio.Reader, hs Handshake, err error) + func (d Dialer) Upgrade(conn io.ReadWriter, u *url.URL) (br *bufio.Reader, hs Handshake, err error) + type Frame struct + Header Header + Payload []byte + func MaskFrame(f Frame) Frame + func MaskFrameInPlace(f Frame) Frame + func MaskFrameInPlaceWith(f Frame, m [4]byte) Frame + func MaskFrameWith(f Frame, mask [4]byte) Frame + func MustReadFrame(r io.Reader) Frame + func NewBinaryFrame(p []byte) Frame + func NewCloseFrame(p []byte) Frame + func NewFrame(op OpCode, fin bool, p []byte) Frame + func NewPingFrame(p []byte) Frame + func NewPongFrame(p []byte) Frame + func NewTextFrame(p []byte) Frame + func ReadFrame(r io.Reader) (f Frame, err error) + func UnmaskFrame(f Frame) Frame + func UnmaskFrameInPlace(f Frame) Frame + type HTTPUpgrader struct + Extension func(httphead.Option) bool + Header http.Header + Negotiate func(httphead.Option) (httphead.Option, error) + Protocol func(string) bool + Timeout time.Duration + var DefaultHTTPUpgrader HTTPUpgrader + func (u HTTPUpgrader) Upgrade(r *http.Request, w http.ResponseWriter) (conn net.Conn, rw *bufio.ReadWriter, hs Handshake, err error) + type Handshake struct + Extensions []httphead.Option + HeaderMap http.Request + Protocol string + func Dial(ctx context.Context, urlstr string) (net.Conn, *bufio.Reader, Handshake, error) + func Upgrade(conn io.ReadWriter) (Handshake, error) + func UpgradeHTTP(r *http.Request, w http.ResponseWriter) (net.Conn, *bufio.ReadWriter, Handshake, error) + type HandshakeHeader interface + type HandshakeHeaderBytes []byte + func (b HandshakeHeaderBytes) WriteTo(w io.Writer) (int64, error) + type HandshakeHeaderFunc func(io.Writer) (int64, error) + func (f HandshakeHeaderFunc) WriteTo(w io.Writer) (int64, error) + type HandshakeHeaderHTTP http.Header + func (h HandshakeHeaderHTTP) WriteTo(w io.Writer) (int64, error) + type HandshakeHeaderString string + func (s HandshakeHeaderString) WriteTo(w io.Writer) (int64, error) + type Header struct + Fin bool + Length int64 + Mask [4]byte + Masked bool + OpCode OpCode + Rsv byte + func ReadHeader(r io.Reader) (h Header, err error) + func (h Header) Rsv1() bool + func (h Header) Rsv2() bool + func (h Header) Rsv3() bool + type OpCode byte + const OpBinary + const OpClose + const OpContinuation + const OpPing + const OpPong + const OpText + func (c OpCode) IsControl() bool + func (c OpCode) IsData() bool + func (c OpCode) IsReserved() bool + type ProtocolError string + func (p ProtocolError) Error() string + type RejectOption func(*ConnectionRejectedError) + func RejectionHeader(h HandshakeHeader) RejectOption + func RejectionReason(reason string) RejectOption + func RejectionStatus(code int) RejectOption + type State uint8 + const StateClientSide + const StateExtended + const StateFragmented + const StateServerSide + func (s State) Clear(v State) State + func (s State) ClientSide() bool + func (s State) Extended() bool + func (s State) Fragmented() bool + func (s State) Is(v State) bool + func (s State) ServerSide() bool + func (s State) Set(v State) State + type StatusCode uint16 + const StatusAbnormalClosure + const StatusGoingAway + const StatusInternalServerError + const StatusInvalidFramePayloadData + const StatusMandatoryExt + const StatusMessageTooBig + const StatusNoMeaningYet + const StatusNoStatusRcvd + const StatusNormalClosure + const StatusPolicyViolation + const StatusProtocolError + const StatusTLSHandshake + const StatusUnsupportedData + func ParseCloseFrameData(payload []byte) (code StatusCode, reason string) + func ParseCloseFrameDataUnsafe(payload []byte) (code StatusCode, reason string) + func (s StatusCode) Empty() bool + func (s StatusCode) In(r StatusCodeRange) bool + func (s StatusCode) IsApplicationSpec() bool + func (s StatusCode) IsNotUsed() bool + func (s StatusCode) IsPrivateSpec() bool + func (s StatusCode) IsProtocolDefined() bool + func (s StatusCode) IsProtocolReserved() bool + func (s StatusCode) IsProtocolSpec() bool + type StatusCodeRange struct + Max StatusCode + Min StatusCode + type StatusError int + func (s StatusError) Error() string + type Upgrader struct + Extension func(httphead.Option) bool + ExtensionCustom func([]byte, []httphead.Option) ([]httphead.Option, bool) + Header HandshakeHeader + Negotiate func(httphead.Option) (httphead.Option, error) + OnBeforeUpgrade func() (header HandshakeHeader, err error) + OnHeader func(key, value []byte) error + OnHost func(host []byte) error + OnRequest func(uri []byte) error + Protocol func([]byte) bool + ProtocolCustom func([]byte) (string, bool) + ReadBufferSize int + WriteBufferSize int + var DefaultUpgrader Upgrader + func (u Upgrader) Upgrade(conn io.ReadWriter) (hs Handshake, err error)