@@ -203,32 +203,37 @@ type StatusCode int
203203
204204// These codes were retrieved from:
205205// https://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number
206+ //
207+ // In addition to the defined constants, 4000-4999 may be used by applications.
206208const (
207- StatusNormalClosure StatusCode = 1000 + iota
208- StatusGoingAway
209- StatusProtocolError
210- StatusUnsupportedData
209+ StatusNormalClosure StatusCode = 1000
210+ StatusGoingAway StatusCode = 1001
211+ StatusProtocolError StatusCode = 1002
212+ StatusUnsupportedData StatusCode = 1003
211213
212- _ // 1004 is reserved.
214+ // 1004 is reserved and so not exported.
215+ statusReserved StatusCode = 1004
213216
214- StatusNoStatusRcvd
217+ // StatusNoStatusRcvd cannot be sent as reserved for when
218+ // a close message is received without an explicit status.
219+ StatusNoStatusRcvd StatusCode = 1005
215220
216- // This StatusCode is only exported for use with Wasm.
221+ // StatusAbnormalClosure is only exported for use with Wasm.
217222 // In non Wasm Go, the returned error will indicate whether the connection was closed or not or what happened.
218- StatusAbnormalClosure
219-
220- StatusInvalidFramePayloadData
221- StatusPolicyViolation
222- StatusMessageTooBig
223- StatusMandatoryExtension
224- StatusInternalError
225- StatusServiceRestart
226- StatusTryAgainLater
227- StatusBadGateway
228-
229- // This StatusCode is only exported for use with Wasm.
223+ StatusAbnormalClosure StatusCode = 1006
224+
225+ StatusInvalidFramePayloadData StatusCode = 1007
226+ StatusPolicyViolation StatusCode = 1008
227+ StatusMessageTooBig StatusCode = 1009
228+ StatusMandatoryExtension StatusCode = 1010
229+ StatusInternalError StatusCode = 1011
230+ StatusServiceRestart StatusCode = 1012
231+ StatusTryAgainLater StatusCode = 1013
232+ StatusBadGateway StatusCode = 1014
233+
234+ // StatusTLSHandshake is only exported for use with Wasm.
230235 // In non Wasm Go, the returned error will indicate whether there was a TLS handshake failure.
231- StatusTLSHandshake
236+ StatusTLSHandshake StatusCode = 1015
232237)
233238
234239// CloseError represents a WebSocket close frame.
@@ -272,7 +277,7 @@ func parseClosePayload(p []byte) (CloseError, error) {
272277// and https://tools.ietf.org/html/rfc6455#section-7.4.1
273278func validWireCloseCode (code StatusCode ) bool {
274279 switch code {
275- case 1004 , StatusNoStatusRcvd , StatusAbnormalClosure , StatusTLSHandshake :
280+ case statusReserved , StatusNoStatusRcvd , StatusAbnormalClosure , StatusTLSHandshake :
276281 return false
277282 }
278283
0 commit comments