|
31 | 31 |
|
32 | 32 | import Foundation
|
33 | 33 |
|
34 |
| -public struct WSCloseCode: RawRepresentable, Sendable, Hashable { |
35 |
| - public var rawValue: UInt16 |
36 |
| - |
37 |
| - public init(rawValue: UInt16) { |
38 |
| - self.rawValue = rawValue |
39 |
| - } |
| 34 | +public struct WSCloseCode: Sendable, Hashable { |
| 35 | + public var code: UInt16 |
| 36 | + public var reason: String |
40 | 37 |
|
41 | 38 | public init(_ code: UInt16) {
|
42 |
| - self.rawValue = code |
| 39 | + self.code = code |
| 40 | + self.reason = "" |
| 41 | + } |
| 42 | + public init(_ code: UInt16, reason: String) { |
| 43 | + self.code = code |
| 44 | + self.reason = reason |
43 | 45 | }
|
44 | 46 | }
|
45 | 47 |
|
46 | 48 | public extension WSCloseCode {
|
47 | 49 | // The following codes are based on:
|
48 | 50 | // https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
|
49 | 51 |
|
50 |
| - static let normalClosure = WSCloseCode(1000) |
51 |
| - static let goingAway = WSCloseCode(1001) |
52 |
| - static let protocolError = WSCloseCode(1002) |
53 |
| - static let unsupportedData = WSCloseCode(1003) |
54 |
| - static let noStatusReceived = WSCloseCode(1005) |
55 |
| - static let abnormalClosure = WSCloseCode(1006) |
56 |
| - static let invalidFramePayloadData = WSCloseCode(1007) |
57 |
| - static let policyViolation = WSCloseCode(1008) |
58 |
| - static let messageTooBig = WSCloseCode(1009) |
59 |
| - static let mandatoryExtensionMissing = WSCloseCode(1010) |
60 |
| - static let internalServerError = WSCloseCode(1011) |
61 |
| - static let serviceRestart = WSCloseCode(1012) |
62 |
| - static let tryAgainLater = WSCloseCode(1013) |
63 |
| - static let badGateway = WSCloseCode(1014) |
64 |
| - static let tlsHandshakeFailure = WSCloseCode(1015) |
| 52 | + static let normalClosure = WSCloseCode(1000) |
| 53 | + static let goingAway = WSCloseCode(1001, reason: "Going Away") |
| 54 | + static let protocolError = WSCloseCode(1002, reason: "Protocol Error") |
| 55 | + static let unsupportedData = WSCloseCode(1003, reason: "Unsupported Data") |
| 56 | + static let noStatusReceived = WSCloseCode(1005, reason: "No Status Received") |
| 57 | + static let abnormalClosure = WSCloseCode(1006, reason: "Abnormal Closure") |
| 58 | + static let invalidFramePayload = WSCloseCode(1007, reason: "Invalid Frame Payload") |
| 59 | + static let policyViolation = WSCloseCode(1008, reason: "Policy Violation") |
| 60 | + static let messageTooBig = WSCloseCode(1009, reason: "Message Too Big") |
| 61 | + static let mandatoryExtensionMissing = WSCloseCode(1010, reason: "Mandatory Extension Missing") |
| 62 | + static let internalServerError = WSCloseCode(1011, reason: "Internal Server Error") |
| 63 | + static let serviceRestart = WSCloseCode(1012, reason: "Service Restart") |
| 64 | + static let tryAgainLater = WSCloseCode(1013, reason: "Try Again Later") |
| 65 | + static let badGateway = WSCloseCode(1014, reason: "Bad Gateway") |
| 66 | + static let tlsHandshakeFailure = WSCloseCode(1015, reason: "TLS Handshake Failure") |
65 | 67 | }
|
0 commit comments