diff --git a/Source/WebSocket.swift b/Source/WebSocket.swift index a6dcbb01..5f7fad11 100644 --- a/Source/WebSocket.swift +++ b/Source/WebSocket.swift @@ -519,14 +519,32 @@ open class WebSocket : NSObject, StreamDelegate { Finds the HTTP Packet in the TCP stream, by looking for the CRLF. */ private func processHTTP(_ buffer: UnsafePointer, bufferLen: Int) -> Int { + // Find the start of the packet + let HTTPBytes = [UInt8(ascii: "H"), UInt8(ascii: "T"), UInt8(ascii: "T"), UInt8(ascii: "P")] + var l = 0 + var startingIndex = 0 + for i in 0.. 0 { - let code = validateResponse(buffer, bufferLen: totalSize) + let code = validateResponse(buffer + startingIndex, bufferLen: totalSize) if code != 0 { return code } totalSize += 1 //skip the last \n - let restSize = bufferLen - totalSize + let restSize = bufferLen - totalSize - startingIndex if restSize > 0 { - processRawMessagesInBuffer(buffer + totalSize, bufferLen: restSize) + processRawMessagesInBuffer(buffer + totalSize + startingIndex, bufferLen: restSize) } return 0 //success }