From 5ee4823daa9d5bd4a96d8585ae75d5cd86138473 Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Thu, 26 Sep 2019 17:27:55 +0200 Subject: [PATCH 1/2] Consolidate status codes --- frame.go | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/frame.go b/frame.go index 95061f5a..cd293a35 100644 --- a/frame.go +++ b/frame.go @@ -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 - 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. @@ -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 } From 2c52a7b465996603cb3ba3ff5967f0558808cebb Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Thu, 26 Sep 2019 18:27:22 +0200 Subject: [PATCH 2/2] unexport statusReserved --- frame.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame.go b/frame.go index cd293a35..ac31ef73 100644 --- a/frame.go +++ b/frame.go @@ -208,7 +208,7 @@ const ( StatusGoingAway StatusCode = 1001 StatusProtocolError StatusCode = 1002 StatusUnsupportedData StatusCode = 1003 - StatusReserved StatusCode = 1004 + statusReserved StatusCode = 1004 StatusNoStatusRcvd StatusCode = 1005 // This StatusCode is only exported for use with Wasm. @@ -270,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 StatusReserved, StatusNoStatusRcvd, StatusAbnormalClosure, StatusTLSHandshake: + case statusReserved, StatusNoStatusRcvd, StatusAbnormalClosure, StatusTLSHandshake: return false }