From d63213528955ad1206e83c061bf5d776960da290 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Tue, 28 Aug 2018 10:46:52 -0400 Subject: [PATCH 1/8] use while let instead of while and if let --- Source/SocketIO/Parse/SocketParsable.swift | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Source/SocketIO/Parse/SocketParsable.swift b/Source/SocketIO/Parse/SocketParsable.swift index 1c8b9637..d181df46 100644 --- a/Source/SocketIO/Parse/SocketParsable.swift +++ b/Source/SocketIO/Parse/SocketParsable.swift @@ -109,14 +109,11 @@ public extension SocketParsable where Self: SocketManagerSpec & SocketDataBuffer if type == .error { reader.advance(by: -1) } else { - while reader.hasNext { - if let int = Int(reader.read(count: 1)) { - idString += String(int) - } else { - reader.advance(by: -2) - break - } + while let int = Int(reader.read(count: 1)) { + idString += String(int) } + + reader.advance(by: -2) } var dataArray = String(message.utf16[message.utf16.index(reader.currentIndex, offsetBy: 1)...])! From 25df8b66fcbc4eb09333bd22839c9e8bf2bc6dd2 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Wed, 29 Aug 2018 10:25:09 -0400 Subject: [PATCH 2/8] Don't need to write DispatchTime --- Source/SocketIO/Engine/SocketEngine.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SocketIO/Engine/SocketEngine.swift b/Source/SocketIO/Engine/SocketEngine.swift index 738bf30a..a29d6079 100644 --- a/Source/SocketIO/Engine/SocketEngine.swift +++ b/Source/SocketIO/Engine/SocketEngine.swift @@ -546,7 +546,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So pongsMissed += 1 write("", withType: .ping, withData: []) - engineQueue.asyncAfter(deadline: DispatchTime.now() + .milliseconds(pingInterval)) {[weak self, id = self.sid] in + engineQueue.asyncAfter(deadline: .now() + .milliseconds(pingInterval)) {[weak self, id = self.sid] in // Make sure not to ping old connections guard let this = self, this.sid == id else { return } From 520ff7239591d0d0e0e3f6729261d512951dde6c Mon Sep 17 00:00:00 2001 From: Erik Little Date: Thu, 30 Aug 2018 09:14:27 -0400 Subject: [PATCH 3/8] Be sure to keep secure config even if config is changed. Fix #1078 --- Source/SocketIO/Manager/SocketManager.swift | 11 ++++++----- Tests/TestSocketIO/SocketMangerTest.swift | 10 ++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Source/SocketIO/Manager/SocketManager.swift b/Source/SocketIO/Manager/SocketManager.swift index 126aec1b..d4407f42 100644 --- a/Source/SocketIO/Manager/SocketManager.swift +++ b/Source/SocketIO/Manager/SocketManager.swift @@ -137,10 +137,6 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa self._config = config self.socketURL = socketURL - if socketURL.absoluteString.hasPrefix("https://") { - self._config.insert(.secure(true)) - } - super.init() setConfigs(_config) @@ -489,12 +485,17 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa DefaultSocketLogger.Logger.log = log case let .logger(logger): DefaultSocketLogger.Logger = logger - default: + case _: continue } } _config = config + + if socketURL.absoluteString.hasPrefix("https://") { + _config.insert(.secure(true)) + } + _config.insert(.path("/socket.io/"), replacing: false) // If `ConfigSettable` & `SocketEngineSpec`, update its configs. diff --git a/Tests/TestSocketIO/SocketMangerTest.swift b/Tests/TestSocketIO/SocketMangerTest.swift index 22da481f..37e5dba4 100644 --- a/Tests/TestSocketIO/SocketMangerTest.swift +++ b/Tests/TestSocketIO/SocketMangerTest.swift @@ -18,6 +18,16 @@ class SocketMangerTest : XCTestCase { XCTAssertEqual(manager.status, .notConnected) } + func testSettingConfig() { + let manager = SocketManager(socketURL: URL(string: "https://example.com/")!) + + XCTAssertEqual(manager.config.first!, .secure(true)) + + manager.config = [] + + XCTAssertEqual(manager.config.first!, .secure(true)) + } + func testManagerCallsConnect() { setUpSockets() From cfa6a217be20dc2f9b17868f99b2d34099e8bd9a Mon Sep 17 00:00:00 2001 From: Hugo Schouman Date: Mon, 3 Sep 2018 15:51:20 +0200 Subject: [PATCH 4/8] fix cookies import when create the websocket --- Source/SocketIO/Engine/SocketEngine.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SocketIO/Engine/SocketEngine.swift b/Source/SocketIO/Engine/SocketEngine.swift index 738bf30a..52076c96 100644 --- a/Source/SocketIO/Engine/SocketEngine.swift +++ b/Source/SocketIO/Engine/SocketEngine.swift @@ -281,7 +281,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So private func createWebSocketAndConnect() { var req = URLRequest(url: urlWebSocketWithSid) - addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies) + addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies(for: urlWebSocketWithSid)) ws = WebSocket(request: req) ws?.callbackQueue = engineQueue From 867db19bc5ee69ddff2beb88c8700fa2ce71aff2 Mon Sep 17 00:00:00 2001 From: Hugo Schouman Date: Wed, 5 Sep 2018 19:26:35 +0200 Subject: [PATCH 5/8] set the right URL in websocket creation --- Source/SocketIO/Engine/SocketEngine.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SocketIO/Engine/SocketEngine.swift b/Source/SocketIO/Engine/SocketEngine.swift index 52076c96..da0cbc0f 100644 --- a/Source/SocketIO/Engine/SocketEngine.swift +++ b/Source/SocketIO/Engine/SocketEngine.swift @@ -281,7 +281,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So private func createWebSocketAndConnect() { var req = URLRequest(url: urlWebSocketWithSid) - addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies(for: urlWebSocketWithSid)) + addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies(for: urlPollingWithSid)) ws = WebSocket(request: req) ws?.callbackQueue = engineQueue From c3032579c031aa3bdc3c4c38e539a76047022607 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Tue, 18 Sep 2018 11:00:18 -0400 Subject: [PATCH 6/8] update xcode versino --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 91243b79..2f387900 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: objective-c xcode_project: Socket.IO-Client-Swift.xcodeproj # path to your xcodeproj folder xcode_scheme: SocketIO-Mac -osx_image: xcode9.2 +osx_image: xcode10 branches: only: - master From e877bb26c3eab6ed40a5a104d32609a44ba97e7d Mon Sep 17 00:00:00 2001 From: Erik Little Date: Tue, 2 Oct 2018 07:53:36 -0400 Subject: [PATCH 7/8] check for 200 status code when polling #857 --- .../Engine/SocketEnginePollable.swift | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Source/SocketIO/Engine/SocketEnginePollable.swift b/Source/SocketIO/Engine/SocketEnginePollable.swift index faec93ab..0e46c3fd 100644 --- a/Source/SocketIO/Engine/SocketEnginePollable.swift +++ b/Source/SocketIO/Engine/SocketEnginePollable.swift @@ -122,9 +122,12 @@ extension SocketEnginePollable { doRequest(for: req) {[weak self] data, res, err in guard let this = self, this.polling else { return } - - if err != nil || data == nil { - DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling") + guard let data = data, let res = res as? HTTPURLResponse, res.statusCode == 200 else { + if let err = err { + DefaultSocketLogger.Logger.error(err.localizedDescription, type: "SocketEnginePolling") + } else { + DefaultSocketLogger.Logger.error("Error during long poll request", type: "SocketEnginePolling") + } if this.polling { this.didError(reason: err?.localizedDescription ?? "Error") @@ -135,7 +138,7 @@ extension SocketEnginePollable { DefaultSocketLogger.Logger.log("Got polling response", type: "SocketEnginePolling") - if let str = String(data: data!, encoding: .utf8) { + if let str = String(data: data, encoding: .utf8) { this.parsePollingMessage(str) } @@ -163,11 +166,14 @@ extension SocketEnginePollable { DefaultSocketLogger.Logger.log("POSTing", type: "SocketEnginePolling") - doRequest(for: req) {[weak self] data, res, err in + doRequest(for: req) {[weak self] _, res, err in guard let this = self else { return } - - if err != nil { - DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling") + guard let res = res as? HTTPURLResponse, res.statusCode == 200 else { + if let err = err { + DefaultSocketLogger.Logger.error(err.localizedDescription, type: "SocketEnginePolling") + } else { + DefaultSocketLogger.Logger.error("Error flushing waiting posts", type: "SocketEnginePolling") + } if this.polling { this.didError(reason: err?.localizedDescription ?? "Error") From d25a926226ecfafcd462a10fb9144d7347681446 Mon Sep 17 00:00:00 2001 From: Erik Little Date: Thu, 4 Oct 2018 05:55:44 -0400 Subject: [PATCH 8/8] update changelog and bump pod version --- CHANGELOG.md | 4 ++++ Socket.IO-Client-Swift.podspec | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 782da411..6e5d99b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v13.3.1 + +- Fixes various bugs. [#857](https://github.com/socketio/socket.io-client-swift/issues/857), [#1078](https://github.com/socketio/socket.io-client-swift/issues/1078) + # v13.3.0 - Copy cookies from polling to WebSockets ([#1057](https://github.com/socketio/socket.io-client-swift/issues/1057), [#1058](https://github.com/socketio/socket.io-client-swift/issues/1058)) diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index 24a9545d..4367b39c 100644 --- a/Socket.IO-Client-Swift.podspec +++ b/Socket.IO-Client-Swift.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Socket.IO-Client-Swift" s.module_name = "SocketIO" - s.version = "13.3.0" + s.version = "13.3.1" s.summary = "Socket.IO-client for iOS and OS X" s.description = <<-DESC Socket.IO-client for iOS and OS X. @@ -18,7 +18,7 @@ Pod::Spec.new do |s| s.requires_arc = true s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", - :tag => 'v13.3.0', + :tag => 'v13.3.1', :submodules => true } s.pod_target_xcconfig = {