Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate status codes #151

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,31 +204,29 @@ type StatusCode int
// These codes were retrieved from:
// https://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number
const (
StatusNormalClosure StatusCode = 1000 + iota
Copy link
Contributor

@nhooyr nhooyr Sep 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 👍 since iota does make it harder to tell what number each status code corresponds to.

StatusGoingAway
StatusProtocolError
StatusUnsupportedData

_ // 1004 is reserved.

StatusNoStatusRcvd
StatusNormalClosure StatusCode = 1000
StatusGoingAway StatusCode = 1001
StatusProtocolError StatusCode = 1002
StatusUnsupportedData StatusCode = 1003
statusReserved StatusCode = 1004
StatusNoStatusRcvd StatusCode = 1005

// This StatusCode 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
StatusAbnormalClosure StatusCode = 1006

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

// This StatusCode 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 +270,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