@@ -67,6 +67,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
67
67
var connected : Bool {
68
68
return self . _connected
69
69
}
70
+ var cookies : [ NSHTTPCookie ] ?
70
71
var pingInterval : Int ?
71
72
var polling : Bool {
72
73
return self . _polling
@@ -79,9 +80,10 @@ public class SocketEngine: NSObject, WebSocketDelegate {
79
80
}
80
81
var ws : WebSocket ?
81
82
82
- init ( client: SocketIOClient , forcePolling: Bool = false ) {
83
+ init ( client: SocketIOClient , forcePolling: Bool = false , withCookies cookies : [ NSHTTPCookie ] ? ) {
83
84
self . client = client
84
85
self . forcePolling = forcePolling
86
+ self . cookies = cookies
85
87
self . session = NSURLSession ( configuration: NSURLSessionConfiguration . ephemeralSessionConfiguration ( ) ,
86
88
delegate: nil , delegateQueue: self . workQueue)
87
89
}
@@ -288,7 +290,13 @@ public class SocketEngine: NSObject, WebSocketDelegate {
288
290
let ( urlPolling, urlWebSocket) = self . createURLs ( params: opts)
289
291
self . urlPolling = urlPolling
290
292
self . urlWebSocket = urlWebSocket
291
- let reqPolling = NSURLRequest ( URL: NSURL ( string: urlPolling + " &b64=1 " ) !)
293
+ let reqPolling = NSMutableURLRequest ( URL: NSURL ( string: urlPolling + " &b64=1 " ) !)
294
+
295
+ if self . cookies != nil {
296
+ let headers = NSHTTPCookie . requestHeaderFieldsWithCookies ( self . cookies!)
297
+ reqPolling. allHTTPHeaderFields = headers
298
+ }
299
+
292
300
293
301
self . session. dataTaskWithRequest ( reqPolling) { [ weak self] data, res, err in
294
302
var err2 : NSError ?
@@ -470,10 +478,10 @@ public class SocketEngine: NSObject, WebSocketDelegate {
470
478
}
471
479
472
480
if self !. websocket {
473
- // println ("sending ws: \(msg):\(datas)")
481
+ // NSLog ("sending ws: \(msg):\(datas)")
474
482
self ? . sendWebSocketMessage ( msg, withType: PacketType . MESSAGE, datas: datas)
475
483
} else {
476
- // println ("sending poll: \(msg):\(datas)")
484
+ // NSLog ("sending poll: \(msg):\(datas)")
477
485
self ? . sendPollMessage ( msg, withType: PacketType . MESSAGE, datas: datas)
478
486
}
479
487
}
0 commit comments