Skip to content

Commit

Permalink
Improve godoc for status codes
Browse files Browse the repository at this point in the history
Closes #151
  • Loading branch information
cristaloleg authored and nhooyr committed Sep 27, 2019
1 parent b371dcc commit 71d69de
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
47 changes: 26 additions & 21 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,32 +203,37 @@ type StatusCode int

// These codes were retrieved from:
// https://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number
//
// In addition to the defined constants, 4000-4999 may be used by applications.
const (
StatusNormalClosure StatusCode = 1000 + iota
StatusGoingAway
StatusProtocolError
StatusUnsupportedData
StatusNormalClosure StatusCode = 1000
StatusGoingAway StatusCode = 1001
StatusProtocolError StatusCode = 1002
StatusUnsupportedData StatusCode = 1003

_ // 1004 is reserved.
// 1004 is reserved and so not exported.
statusReserved StatusCode = 1004

StatusNoStatusRcvd
// StatusNoStatusRcvd cannot be sent as reserved for when
// a close message is received without an explicit status.
StatusNoStatusRcvd StatusCode = 1005

// This StatusCode is only exported for use with Wasm.
// StatusAbnormalClosure is only exported for use with Wasm.
// In non Wasm Go, the returned error will indicate whether the connection was closed or not or what happened.
StatusAbnormalClosure

StatusInvalidFramePayloadData
StatusPolicyViolation
StatusMessageTooBig
StatusMandatoryExtension
StatusInternalError
StatusServiceRestart
StatusTryAgainLater
StatusBadGateway

// This StatusCode is only exported for use with Wasm.
StatusAbnormalClosure StatusCode = 1006

StatusInvalidFramePayloadData StatusCode = 1007
StatusPolicyViolation StatusCode = 1008
StatusMessageTooBig StatusCode = 1009
StatusMandatoryExtension StatusCode = 1010
StatusInternalError StatusCode = 1011
StatusServiceRestart StatusCode = 1012
StatusTryAgainLater StatusCode = 1013
StatusBadGateway StatusCode = 1014

// StatusTLSHandshake is only exported for use with Wasm.
// In non Wasm Go, the returned error will indicate whether there was a TLS handshake failure.
StatusTLSHandshake
StatusTLSHandshake StatusCode = 1015
)

// CloseError represents a WebSocket close frame.
Expand Down Expand Up @@ -272,7 +277,7 @@ func parseClosePayload(p []byte) (CloseError, error) {
// and https://tools.ietf.org/html/rfc6455#section-7.4.1
func validWireCloseCode(code StatusCode) bool {
switch code {
case 1004, StatusNoStatusRcvd, StatusAbnormalClosure, StatusTLSHandshake:
case statusReserved, StatusNoStatusRcvd, StatusAbnormalClosure, StatusTLSHandshake:
return false
}

Expand Down
24 changes: 7 additions & 17 deletions frame_stringer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 71d69de

Please sign in to comment.