diff --git a/CHANGELOG.md b/CHANGELOG.md index 4150071a..35f2b7b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,10 @@ All notable changes to this project will be documented in this file. Changes not ## Fixed - An issue in the `HttpRouter` causing issues to handle routes with overlapping in the tail. ([#379](https://github.com/httpswift/swifter/pull/359), [#382](https://github.com/httpswift/swifter/pull/382)) by [@Vkt0r](https://github.com/Vkt0r) +## Changed +- Performance: Batch reads of websocket payloads rather than reading byte-by-byte. ([#387](https://github.com/httpswift/swifter/pull/387)) by [@lynaghk](https://github.com/lynaghk) + + # [1.4.6] ## Added - The `.movedTemporarily` case (HTTP 307) to possibles HTTP responses. ([#352](https://github.com/httpswift/swifter/pull/352)) by [@csch](https://github.com/csch) diff --git a/Sources/WebSockets.swift b/Sources/WebSockets.swift index 5eaf32b9..097c7752 100644 --- a/Sources/WebSockets.swift +++ b/Sources/WebSockets.swift @@ -276,9 +276,12 @@ public class WebSocketSession: Hashable, Equatable { let b7 = UInt64(try socket.read()) len = UInt64(littleEndian: b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7) } + let mask = [try socket.read(), try socket.read(), try socket.read(), try socket.read()] + //Read payload all at once, then apply mask (calling `socket.read` byte-by-byte is super slow). + frm.payload = try socket.read(length: Int(len)) for i in 0..