Skip to content

Commit 3525cae

Browse files
committed
Implement socketio#684
1 parent 943e94e commit 3525cae

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

Source/SocketIO/Engine/SocketEngine.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
4444
}
4545
}
4646

47+
/// A dictionary of extra http headers that will be set during connection.
48+
public var extraHeaders: [String: String]?
49+
4750
/// A queue of engine.io messages waiting for POSTing
4851
///
4952
/// **You should not touch this directly**
@@ -73,9 +76,6 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
7376
/// An array of HTTPCookies that are sent during the connection.
7477
public private(set) var cookies: [HTTPCookie]?
7578

76-
/// A dictionary of extra http headers that will be set during connection.
77-
public private(set) var extraHeaders: [String: String]?
78-
7979
/// When `true`, the engine is in the process of switching to WebSockets.
8080
///
8181
/// **Do not touch this directly**

Source/SocketIO/Engine/SocketEngineSpec.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import Starscream
5252
var engineQueue: DispatchQueue { get }
5353

5454
/// A dictionary of extra http headers that will be set during connection.
55-
var extraHeaders: [String: String]? { get }
55+
var extraHeaders: [String: String]? { get set }
5656

5757
/// When `true`, the engine is in the process of switching to WebSockets.
5858
var fastUpgrade: Bool { get }

Tests/TestSocketIO/SocketEngineTest.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ class SocketEngineTest: XCTestCase {
192192
XCTAssertTrue(manager.engine!.forceWebsockets)
193193
}
194194

195+
func testChangingEngineHeadersAfterInit() {
196+
engine.extraHeaders = ["Hello": "World"]
197+
198+
let req = engine.createRequestForPostWithPostWait()
199+
200+
XCTAssertEqual("World", req.allHTTPHeaderFields?["Hello"])
201+
}
202+
195203
var manager: SocketManager!
196204
var socket: SocketIOClient!
197205
var engine: SocketEngine!

Tests/TestSocketIO/SocketSideEffectTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ class TestEngine : SocketEngineSpec {
450450
var connectParams: [String: Any]? = nil
451451
private(set) var cookies: [HTTPCookie]? = nil
452452
private(set) var engineQueue = DispatchQueue.main
453-
private(set) var extraHeaders: [String: String]? = nil
453+
var extraHeaders: [String: String]? = nil
454454
private(set) var fastUpgrade = false
455455
private(set) var forcePolling = false
456456
private(set) var forceWebsockets = false

0 commit comments

Comments
 (0)