Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nuclearace committed Oct 4, 2018
2 parents a3d4432 + d25a926 commit 016e127
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
4 changes: 2 additions & 2 deletions Socket.IO-Client-Swift.podspec
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions Source/SocketIO/Engine/SocketEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: urlPollingWithSid))

ws = WebSocket(request: req)
ws?.callbackQueue = engineQueue
Expand Down Expand Up @@ -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 }

Expand Down
22 changes: 14 additions & 8 deletions Source/SocketIO/Engine/SocketEnginePollable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
}

Expand Down Expand Up @@ -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")
Expand Down
11 changes: 6 additions & 5 deletions Source/SocketIO/Manager/SocketManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 4 additions & 7 deletions Source/SocketIO/Parse/SocketParsable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)...])!
Expand Down
10 changes: 10 additions & 0 deletions Tests/TestSocketIO/SocketMangerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 016e127

Please sign in to comment.