Skip to content

Commit d03e319

Browse files
authored
Merge pull request #1059 from socketio/development
v13.3.0
2 parents cc90426 + 165ec25 commit d03e319

8 files changed

+24
-14
lines changed

Diff for: Source/SocketIO/Client/SocketIOClientSpec.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Dispatch
2626
import Foundation
2727

2828
/// Defines the interface for a SocketIOClient.
29-
public protocol SocketIOClientSpec : class {
29+
public protocol SocketIOClientSpec : AnyObject {
3030
// MARK: Properties
3131

3232
/// A handler that will be called on any event.

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

+1-1
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)
284+
addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies)
285285

286286
ws = WebSocket(request: req)
287287
ws?.callbackQueue = engineQueue

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,14 @@ extension SocketEngineSpec {
155155
return com.url!
156156
}
157157

158-
func addHeaders(to req: inout URLRequest) {
159-
if let cookies = cookies {
160-
req.allHTTPHeaderFields = HTTPCookie.requestHeaderFields(with: cookies)
158+
func addHeaders(to req: inout URLRequest, includingCookies additionalCookies: [HTTPCookie]? = nil) {
159+
var cookiesToAdd: [HTTPCookie] = cookies ?? []
160+
cookiesToAdd += additionalCookies ?? []
161+
162+
if !cookiesToAdd.isEmpty {
163+
req.allHTTPHeaderFields = HTTPCookie.requestHeaderFields(with: cookiesToAdd)
161164
}
162-
165+
163166
if let extraHeaders = extraHeaders {
164167
for (headerName, value) in extraHeaders {
165168
req.setValue(value, forHTTPHeaderField: headerName)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa
392392

393393
private func _parseEngineMessage(_ msg: String) {
394394
guard let packet = parseSocketMessage(msg) else { return }
395-
guard packet.type != .binaryAck && packet.type != .binaryEvent else {
395+
guard !packet.type.isBinary else {
396396
waitingPackets.append(packet)
397397

398398
return

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import Foundation
4646
/// or call one of the `disconnectSocket` methods on this class.
4747
///
4848
@objc
49-
public protocol SocketManagerSpec : class, SocketEngineClient {
49+
public protocol SocketManagerSpec : AnyObject, SocketEngineClient {
5050
// MARK: Properties
5151

5252
/// Returns the socket associated with the default namespace ("/").

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public struct SocketPacket : CustomStringConvertible {
116116
private func createPacketString() -> String {
117117
let typeString = String(type.rawValue)
118118
// Binary count?
119-
let binaryCountString = typeString + (type == .binaryEvent || type == .binaryAck ? "\(String(binary.count))-" : "")
119+
let binaryCountString = typeString + (type.isBinary ? "\(String(binary.count))-" : "")
120120
// Namespace?
121121
let nspString = binaryCountString + (nsp != "/" ? "\(nsp)," : "")
122122
// Ack number?
@@ -181,6 +181,13 @@ public extension SocketPacket {
181181

182182
/// Binary Ack: 6
183183
case binaryAck
184+
185+
// MARK: Properties
186+
187+
/// Whether or not this type is binary
188+
public var isBinary: Bool {
189+
return self == .binaryAck || self == .binaryEvent
190+
}
184191
}
185192
}
186193

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import Foundation
2424

2525
/// Defines that a type will be able to parse socket.io-protocol messages.
26-
public protocol SocketParsable : class {
26+
public protocol SocketParsable : AnyObject {
2727
// MARK: Methods
2828

2929
/// Called when the engine has received some binary data that should be attached to a packet.
@@ -57,7 +57,7 @@ public enum SocketParsableError : Error {
5757
}
5858

5959
/// Says that a type will be able to buffer binary data before all data for an event has come in.
60-
public protocol SocketDataBufferable : class {
60+
public protocol SocketDataBufferable : AnyObject {
6161
// MARK: Properties
6262

6363
/// A list of packets that are waiting for binary data.
@@ -77,7 +77,7 @@ public extension SocketParsable where Self: SocketManagerSpec & SocketDataBuffer
7777
internal func parseString(_ message: String) throws -> SocketPacket {
7878
var reader = SocketStringReader(message: message)
7979

80-
guard let type = Int(reader.read(count: 1)).flatMap({ SocketPacket.PacketType(rawValue: $0) }) else {
80+
guard let type = Int(reader.read(count: 1)).flatMap({ SocketPacket.PacketType(rawValue: $0) }) else {
8181
throw SocketParsableError.invalidPacketType
8282
}
8383

@@ -88,7 +88,7 @@ public extension SocketParsable where Self: SocketManagerSpec & SocketDataBuffer
8888
var namespace = "/"
8989
var placeholders = -1
9090

91-
if type == .binaryEvent || type == .binaryAck {
91+
if type.isBinary {
9292
if let holders = Int(reader.readUntilOccurence(of: "-")) {
9393
placeholders = holders
9494
} else {

Diff for: Source/SocketIO/Util/SocketLogger.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import Foundation
2626

2727
/// Represents a class will log client events.
28-
public protocol SocketLogger : class {
28+
public protocol SocketLogger : AnyObject {
2929
// MARK: Properties
3030

3131
/// Whether to log or not

0 commit comments

Comments
 (0)