Explorar o código

Control messages must not be fragmented.

Mathieu Barnachon %!s(int64=10) %!d(string=hai) anos
pai
achega
cbe77e31ea
Modificáronse 1 ficheiros con 10 adicións e 0 borrados
  1. 10 0
      Sources/WebSockets.swift

+ 10 - 0
Sources/WebSockets.swift

@@ -163,6 +163,16 @@ public class WebSocketSession: Hashable, Equatable  {
             // http://tools.ietf.org/html/rfc6455#section-5.2 ( Page 29 )
             throw Error.UnknownOpCode("\(opc)")
         }
+        if frm.fin == false {
+            switch opcode {
+            case .Ping, .Pong, .Close:
+                // Control frames must not be fragmented
+                // https://tools.ietf.org/html/rfc6455#section-5.5 ( Page 35 )
+                throw Error.ProtocolError("control frames must not be framgemted.")
+            default:
+                break
+            }
+        }
         frm.opcode = opcode
         let sec = try socket.read()
         let msk = sec & 0x80 != 0