Skip to content

v13.3.0 #1059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 29, 2018
Merged
2 changes: 1 addition & 1 deletion Source/SocketIO/Client/SocketIOClientSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Dispatch
import Foundation

/// Defines the interface for a SocketIOClient.
public protocol SocketIOClientSpec : class {
public protocol SocketIOClientSpec : AnyObject {
// MARK: Properties

/// A handler that will be called on any event.
Expand Down
2 changes: 1 addition & 1 deletion 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)
addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies)

ws = WebSocket(request: req)
ws?.callbackQueue = engineQueue
Expand Down
11 changes: 7 additions & 4 deletions Source/SocketIO/Engine/SocketEngineSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ extension SocketEngineSpec {
return com.url!
}

func addHeaders(to req: inout URLRequest) {
if let cookies = cookies {
req.allHTTPHeaderFields = HTTPCookie.requestHeaderFields(with: cookies)
func addHeaders(to req: inout URLRequest, includingCookies additionalCookies: [HTTPCookie]? = nil) {
var cookiesToAdd: [HTTPCookie] = cookies ?? []
cookiesToAdd += additionalCookies ?? []

if !cookiesToAdd.isEmpty {
req.allHTTPHeaderFields = HTTPCookie.requestHeaderFields(with: cookiesToAdd)
}

if let extraHeaders = extraHeaders {
for (headerName, value) in extraHeaders {
req.setValue(value, forHTTPHeaderField: headerName)
Expand Down
2 changes: 1 addition & 1 deletion Source/SocketIO/Manager/SocketManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa

private func _parseEngineMessage(_ msg: String) {
guard let packet = parseSocketMessage(msg) else { return }
guard packet.type != .binaryAck && packet.type != .binaryEvent else {
guard !packet.type.isBinary else {
waitingPackets.append(packet)

return
Expand Down
2 changes: 1 addition & 1 deletion Source/SocketIO/Manager/SocketManagerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import Foundation
/// or call one of the `disconnectSocket` methods on this class.
///
@objc
public protocol SocketManagerSpec : class, SocketEngineClient {
public protocol SocketManagerSpec : AnyObject, SocketEngineClient {
// MARK: Properties

/// Returns the socket associated with the default namespace ("/").
Expand Down
9 changes: 8 additions & 1 deletion Source/SocketIO/Parse/SocketPacket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public struct SocketPacket : CustomStringConvertible {
private func createPacketString() -> String {
let typeString = String(type.rawValue)
// Binary count?
let binaryCountString = typeString + (type == .binaryEvent || type == .binaryAck ? "\(String(binary.count))-" : "")
let binaryCountString = typeString + (type.isBinary ? "\(String(binary.count))-" : "")
// Namespace?
let nspString = binaryCountString + (nsp != "/" ? "\(nsp)," : "")
// Ack number?
Expand Down Expand Up @@ -181,6 +181,13 @@ public extension SocketPacket {

/// Binary Ack: 6
case binaryAck

// MARK: Properties

/// Whether or not this type is binary
public var isBinary: Bool {
return self == .binaryAck || self == .binaryEvent
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions Source/SocketIO/Parse/SocketParsable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import Foundation

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

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

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

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

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

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

if type == .binaryEvent || type == .binaryAck {
if type.isBinary {
if let holders = Int(reader.readUntilOccurence(of: "-")) {
placeholders = holders
} else {
Expand Down
2 changes: 1 addition & 1 deletion Source/SocketIO/Util/SocketLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import Foundation

/// Represents a class will log client events.
public protocol SocketLogger : class {
public protocol SocketLogger : AnyObject {
// MARK: Properties

/// Whether to log or not
Expand Down