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
This commit is contained in:
Erik Little 2018-10-04 05:56:16 -04:00
commit 016e12720d
No known key found for this signature in database
GPG Key ID: 62F837E56F4E9320
8 changed files with 43 additions and 25 deletions

View File

@ -1,7 +1,7 @@
language: objective-c language: objective-c
xcode_project: Socket.IO-Client-Swift.xcodeproj # path to your xcodeproj folder xcode_project: Socket.IO-Client-Swift.xcodeproj # path to your xcodeproj folder
xcode_scheme: SocketIO-Mac xcode_scheme: SocketIO-Mac
osx_image: xcode9.2 osx_image: xcode10
branches: branches:
only: only:
- master - master

View File

@ -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 # 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)) - 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))

View File

@ -1,7 +1,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "Socket.IO-Client-Swift" s.name = "Socket.IO-Client-Swift"
s.module_name = "SocketIO" 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.summary = "Socket.IO-client for iOS and OS X"
s.description = <<-DESC s.description = <<-DESC
Socket.IO-client for iOS and OS X. Socket.IO-client for iOS and OS X.
@ -18,7 +18,7 @@ Pod::Spec.new do |s|
s.requires_arc = true s.requires_arc = true
s.source = { s.source = {
:git => "https://github.com/socketio/socket.io-client-swift.git", :git => "https://github.com/socketio/socket.io-client-swift.git",
:tag => 'v13.3.0', :tag => 'v13.3.1',
:submodules => true :submodules => true
} }
s.pod_target_xcconfig = { s.pod_target_xcconfig = {

View File

@ -281,7 +281,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
private func createWebSocketAndConnect() { private func createWebSocketAndConnect() {
var req = URLRequest(url: urlWebSocketWithSid) 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 = WebSocket(request: req)
ws?.callbackQueue = engineQueue ws?.callbackQueue = engineQueue
@ -546,7 +546,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
pongsMissed += 1 pongsMissed += 1
write("", withType: .ping, withData: []) 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 // Make sure not to ping old connections
guard let this = self, this.sid == id else { return } guard let this = self, this.sid == id else { return }

View File

@ -122,9 +122,12 @@ extension SocketEnginePollable {
doRequest(for: req) {[weak self] data, res, err in doRequest(for: req) {[weak self] data, res, err in
guard let this = self, this.polling else { return } guard let this = self, this.polling else { return }
guard let data = data, let res = res as? HTTPURLResponse, res.statusCode == 200 else {
if err != nil || data == nil { if let err = err {
DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling") DefaultSocketLogger.Logger.error(err.localizedDescription, type: "SocketEnginePolling")
} else {
DefaultSocketLogger.Logger.error("Error during long poll request", type: "SocketEnginePolling")
}
if this.polling { if this.polling {
this.didError(reason: err?.localizedDescription ?? "Error") this.didError(reason: err?.localizedDescription ?? "Error")
@ -135,7 +138,7 @@ extension SocketEnginePollable {
DefaultSocketLogger.Logger.log("Got polling response", type: "SocketEnginePolling") 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) this.parsePollingMessage(str)
} }
@ -163,11 +166,14 @@ extension SocketEnginePollable {
DefaultSocketLogger.Logger.log("POSTing", type: "SocketEnginePolling") 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 } guard let this = self else { return }
guard let res = res as? HTTPURLResponse, res.statusCode == 200 else {
if err != nil { if let err = err {
DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling") DefaultSocketLogger.Logger.error(err.localizedDescription, type: "SocketEnginePolling")
} else {
DefaultSocketLogger.Logger.error("Error flushing waiting posts", type: "SocketEnginePolling")
}
if this.polling { if this.polling {
this.didError(reason: err?.localizedDescription ?? "Error") this.didError(reason: err?.localizedDescription ?? "Error")

View File

@ -137,10 +137,6 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa
self._config = config self._config = config
self.socketURL = socketURL self.socketURL = socketURL
if socketURL.absoluteString.hasPrefix("https://") {
self._config.insert(.secure(true))
}
super.init() super.init()
setConfigs(_config) setConfigs(_config)
@ -489,12 +485,17 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa
DefaultSocketLogger.Logger.log = log DefaultSocketLogger.Logger.log = log
case let .logger(logger): case let .logger(logger):
DefaultSocketLogger.Logger = logger DefaultSocketLogger.Logger = logger
default: case _:
continue continue
} }
} }
_config = config _config = config
if socketURL.absoluteString.hasPrefix("https://") {
_config.insert(.secure(true))
}
_config.insert(.path("/socket.io/"), replacing: false) _config.insert(.path("/socket.io/"), replacing: false)
// If `ConfigSettable` & `SocketEngineSpec`, update its configs. // If `ConfigSettable` & `SocketEngineSpec`, update its configs.

View File

@ -109,14 +109,11 @@ public extension SocketParsable where Self: SocketManagerSpec & SocketDataBuffer
if type == .error { if type == .error {
reader.advance(by: -1) reader.advance(by: -1)
} else { } else {
while reader.hasNext { while let int = Int(reader.read(count: 1)) {
if let int = Int(reader.read(count: 1)) { idString += String(int)
idString += String(int)
} else {
reader.advance(by: -2)
break
}
} }
reader.advance(by: -2)
} }
var dataArray = String(message.utf16[message.utf16.index(reader.currentIndex, offsetBy: 1)...])! var dataArray = String(message.utf16[message.utf16.index(reader.currentIndex, offsetBy: 1)...])!

View File

@ -18,6 +18,16 @@ class SocketMangerTest : XCTestCase {
XCTAssertEqual(manager.status, .notConnected) 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() { func testManagerCallsConnect() {
setUpSockets() setUpSockets()