Skip to content

Commit 016e127

Browse files
committed
Merge branch 'development'
* development: update changelog and bump pod version check for 200 status code when polling #857 update xcode versino set the right URL in websocket creation fix cookies import when create the websocket Be sure to keep secure config even if config is changed. Fix #1078 Don't need to write DispatchTime use while let instead of while and if let
2 parents a3d4432 + d25a926 commit 016e127

File tree

8 files changed

+43
-25
lines changed

8 files changed

+43
-25
lines changed

Diff for: .travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: objective-c
22
xcode_project: Socket.IO-Client-Swift.xcodeproj # path to your xcodeproj folder
33
xcode_scheme: SocketIO-Mac
4-
osx_image: xcode9.2
4+
osx_image: xcode10
55
branches:
66
only:
77
- master

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v13.3.1
2+
3+
- 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)
4+
15
# v13.3.0
26

37
- 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 for: Socket.IO-Client-Swift.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "Socket.IO-Client-Swift"
33
s.module_name = "SocketIO"
4-
s.version = "13.3.0"
4+
s.version = "13.3.1"
55
s.summary = "Socket.IO-client for iOS and OS X"
66
s.description = <<-DESC
77
Socket.IO-client for iOS and OS X.
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
1818
s.requires_arc = true
1919
s.source = {
2020
:git => "https://github.com/socketio/socket.io-client-swift.git",
21-
:tag => 'v13.3.0',
21+
:tag => 'v13.3.1',
2222
:submodules => true
2323
}
2424
s.pod_target_xcconfig = {

Diff for: Source/SocketIO/Engine/SocketEngine.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
281281
private func createWebSocketAndConnect() {
282282
var req = URLRequest(url: urlWebSocketWithSid)
283283

284-
addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies)
284+
addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies(for: urlPollingWithSid))
285285

286286
ws = WebSocket(request: req)
287287
ws?.callbackQueue = engineQueue
@@ -546,7 +546,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
546546
pongsMissed += 1
547547
write("", withType: .ping, withData: [])
548548

549-
engineQueue.asyncAfter(deadline: DispatchTime.now() + .milliseconds(pingInterval)) {[weak self, id = self.sid] in
549+
engineQueue.asyncAfter(deadline: .now() + .milliseconds(pingInterval)) {[weak self, id = self.sid] in
550550
// Make sure not to ping old connections
551551
guard let this = self, this.sid == id else { return }
552552

Diff for: Source/SocketIO/Engine/SocketEnginePollable.swift

+14-8
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ extension SocketEnginePollable {
122122

123123
doRequest(for: req) {[weak self] data, res, err in
124124
guard let this = self, this.polling else { return }
125-
126-
if err != nil || data == nil {
127-
DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling")
125+
guard let data = data, let res = res as? HTTPURLResponse, res.statusCode == 200 else {
126+
if let err = err {
127+
DefaultSocketLogger.Logger.error(err.localizedDescription, type: "SocketEnginePolling")
128+
} else {
129+
DefaultSocketLogger.Logger.error("Error during long poll request", type: "SocketEnginePolling")
130+
}
128131

129132
if this.polling {
130133
this.didError(reason: err?.localizedDescription ?? "Error")
@@ -135,7 +138,7 @@ extension SocketEnginePollable {
135138

136139
DefaultSocketLogger.Logger.log("Got polling response", type: "SocketEnginePolling")
137140

138-
if let str = String(data: data!, encoding: .utf8) {
141+
if let str = String(data: data, encoding: .utf8) {
139142
this.parsePollingMessage(str)
140143
}
141144

@@ -163,11 +166,14 @@ extension SocketEnginePollable {
163166

164167
DefaultSocketLogger.Logger.log("POSTing", type: "SocketEnginePolling")
165168

166-
doRequest(for: req) {[weak self] data, res, err in
169+
doRequest(for: req) {[weak self] _, res, err in
167170
guard let this = self else { return }
168-
169-
if err != nil {
170-
DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling")
171+
guard let res = res as? HTTPURLResponse, res.statusCode == 200 else {
172+
if let err = err {
173+
DefaultSocketLogger.Logger.error(err.localizedDescription, type: "SocketEnginePolling")
174+
} else {
175+
DefaultSocketLogger.Logger.error("Error flushing waiting posts", type: "SocketEnginePolling")
176+
}
171177

172178
if this.polling {
173179
this.didError(reason: err?.localizedDescription ?? "Error")

Diff for: Source/SocketIO/Manager/SocketManager.swift

+6-5
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa
137137
self._config = config
138138
self.socketURL = socketURL
139139

140-
if socketURL.absoluteString.hasPrefix("https://") {
141-
self._config.insert(.secure(true))
142-
}
143-
144140
super.init()
145141

146142
setConfigs(_config)
@@ -489,12 +485,17 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa
489485
DefaultSocketLogger.Logger.log = log
490486
case let .logger(logger):
491487
DefaultSocketLogger.Logger = logger
492-
default:
488+
case _:
493489
continue
494490
}
495491
}
496492

497493
_config = config
494+
495+
if socketURL.absoluteString.hasPrefix("https://") {
496+
_config.insert(.secure(true))
497+
}
498+
498499
_config.insert(.path("/socket.io/"), replacing: false)
499500

500501
// If `ConfigSettable` & `SocketEngineSpec`, update its configs.

Diff for: Source/SocketIO/Parse/SocketParsable.swift

+4-7
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,11 @@ public extension SocketParsable where Self: SocketManagerSpec & SocketDataBuffer
109109
if type == .error {
110110
reader.advance(by: -1)
111111
} else {
112-
while reader.hasNext {
113-
if let int = Int(reader.read(count: 1)) {
114-
idString += String(int)
115-
} else {
116-
reader.advance(by: -2)
117-
break
118-
}
112+
while let int = Int(reader.read(count: 1)) {
113+
idString += String(int)
119114
}
115+
116+
reader.advance(by: -2)
120117
}
121118

122119
var dataArray = String(message.utf16[message.utf16.index(reader.currentIndex, offsetBy: 1)...])!

Diff for: Tests/TestSocketIO/SocketMangerTest.swift

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ class SocketMangerTest : XCTestCase {
1818
XCTAssertEqual(manager.status, .notConnected)
1919
}
2020

21+
func testSettingConfig() {
22+
let manager = SocketManager(socketURL: URL(string: "https://example.com/")!)
23+
24+
XCTAssertEqual(manager.config.first!, .secure(true))
25+
26+
manager.config = []
27+
28+
XCTAssertEqual(manager.config.first!, .secure(true))
29+
}
30+
2131
func testManagerCallsConnect() {
2232
setUpSockets()
2333

0 commit comments

Comments
 (0)