From 23fa0aaf0b16db7643c2589a65bf1e09ff257546 Mon Sep 17 00:00:00 2001 From: Anian Schleyer <98647423+anian03@users.noreply.github.com> Date: Sat, 28 Dec 2024 17:50:40 +0100 Subject: [PATCH] `StompClient`: Unzip compressed websocket messages (#109) * Unzip compressed websocket messages * Add warning for failed decompression --- Package.resolved | 26 +++++++++---------- Package.swift | 4 ++- .../StompClient/ArtemisStompClient.swift | 12 ++++++++- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Package.resolved b/Package.resolved index 2eef301..2b4f205 100644 --- a/Package.resolved +++ b/Package.resolved @@ -18,6 +18,15 @@ "version" : "1.8.2" } }, + { + "identity" : "gzipswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/1024jp/GzipSwift.git", + "state" : { + "revision" : "56bf51fdd2fe4b2cf254b2cf34aede3d7caccc6c", + "version" : "6.1.0" + } + }, { "identity" : "kingfisher", "kind" : "remoteSourceControl", @@ -50,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/ashleymills/Reachability.swift", "state" : { - "revision" : "98e968e7b6c1318fb61df23e347bc319761e8acb", - "version" : "5.0.0" + "revision" : "21d1dc412cfecbe6e34f1f4c4eb88d3f912654a6", + "version" : "5.2.4" } }, { @@ -63,15 +72,6 @@ "version" : "0.35.0" } }, - { - "identity" : "starscream", - "kind" : "remoteSourceControl", - "location" : "https://github.com/daltoniam/Starscream.git", - "state" : { - "revision" : "df8d82047f6654d8e4b655d1b1525c64e1059d21", - "version" : "4.0.4" - } - }, { "identity" : "swift-argument-parser", "kind" : "remoteSourceControl", @@ -113,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Romixery/SwiftStomp.git", "state" : { - "revision" : "99dcfa7f428485b92de2359c9df9c778fd2d5599", - "version" : "1.1.1" + "revision" : "f25926d2ab67ec0391de9a706cf71dfb08d36bbc", + "version" : "1.2.1" } }, { diff --git a/Package.swift b/Package.swift index 0a3b49a..9a95130 100644 --- a/Package.swift +++ b/Package.swift @@ -52,6 +52,7 @@ let package = Package( .package(url: "https://github.com/Romixery/SwiftStomp.git", .upToNextMinor(from: "1.2.1")), .package(url: "https://github.com/realm/SwiftLint.git", .upToNextMinor(from: "0.55.0")), .package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver.git", .upToNextMajor(from: "1.9.0")), + .package(url: "https://github.com/1024jp/GzipSwift.git", .upToNextMajor(from: "6.1.0")), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. @@ -77,7 +78,8 @@ let package = Package( dependencies: [ "Common", "SwiftStomp", - "UserStore" + "UserStore", + .product(name: "Gzip", package: "GzipSwift") ], plugins: [ .plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint") diff --git a/Sources/APIClient/StompClient/ArtemisStompClient.swift b/Sources/APIClient/StompClient/ArtemisStompClient.swift index 78a9e29..fa279ae 100644 --- a/Sources/APIClient/StompClient/ArtemisStompClient.swift +++ b/Sources/APIClient/StompClient/ArtemisStompClient.swift @@ -6,6 +6,7 @@ // import Foundation +import Gzip import SwiftStomp import UserStore import Common @@ -125,7 +126,16 @@ extension ArtemisStompClient: SwiftStompDelegate { public func onMessageReceived(swiftStomp: SwiftStomp, message: Any?, messageId: String, destination: String, headers: [String: String]) { log.debug("Stomp: MessageReceived") let continuation = continuations[destination] - continuation?.yield(message) + + if headers["compressed"] == "true" { + if let unzipped = try? (message as? Data)?.gunzipped() { + continuation?.yield(unzipped) + } else { + log.warning("Stomp: Failed to gunzip compressed message") + } + } else { + continuation?.yield(message) + } } public func onReceipt(swiftStomp: SwiftStomp, receiptId: String) {