Skip to content
Open
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
7 changes: 5 additions & 2 deletions Sources/KituraWebSocket/WebSocketConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ public class WebSocketConnection {
return
}
} else if frame.payload.length == 0 {
reasonCode = .noReasonCodeSent
connectionClosed(reason: .noReasonCodeSent, reasonToSendBack: .normal)
return
} else {
connectionClosed(reason: .protocolError, description: "Close frames, which contain a payload, must be between 2 and 125 octets inclusive")
return
Expand Down Expand Up @@ -286,6 +287,7 @@ public class WebSocketConnection {
}

case .ping:
guard active else { break }
guard frame.payload.length < 126 else {
connectionClosed(reason: .protocolError, description: "Control frames are only allowed to have payload up to and including 125 octets")
return
Expand All @@ -296,6 +298,7 @@ public class WebSocketConnection {
}
sendMessage(withOpCode: .pong, payload: frame.payload.bytes, payloadLength: frame.payload.length)


case .pong:
break

Expand Down Expand Up @@ -380,7 +383,7 @@ public class WebSocketConnection {
}
if abs(lastFrameReceivedAt.timeIntervalSinceNow) > (Double(connectionTimeout) * 0.4) {
if abs(lastFrameReceivedAt.timeIntervalSinceNow) > (Double(connectionTimeout)) {
strongSelf.connectionClosed(reason: .closedAbnormally)
strongSelf.connectionClosed(reason: .closedAbnormally, description: "Client failed to respond to a heartbeat ping with a pong", reasonToSendBack: .protocolError)
return
}
strongSelf.ping()
Expand Down