Skip to content

Commit ef1bdb5

Browse files
committed
chore(ios): simplify DDPClient URLSession delegate wiring
Drop the retained urlSessionChallengeDelegate ivar (URLSession already retains its delegate) and collapse the duplicated task-level challenge method since URLSessionDelegate's session-level method handles all challenges when implemented.
1 parent 2c468be commit ef1bdb5

1 file changed

Lines changed: 3 additions & 17 deletions

File tree

ios/Libraries/DDPClient.swift

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ final class DDPClient {
1515

1616
private var webSocketTask: URLSessionWebSocketTask?
1717
private var urlSession: URLSession?
18-
/// Retains the delegate passed to `URLSession` so TLS challenges reuse `Challenge` from `SSLPinning.mm`.
19-
private var urlSessionChallengeDelegate: DDPClientURLSessionChallengeDelegate?
2018
private var sendCounter = 0
2119
private var isConnected = false
2220

@@ -45,11 +43,9 @@ final class DDPClient {
4543
print("[\(Self.TAG)] Connecting to \(wsUrl)")
4644
#endif
4745

48-
let challengeDelegate = DDPClientURLSessionChallengeDelegate()
49-
let session = URLSession(configuration: .default, delegate: challengeDelegate, delegateQueue: nil)
46+
let session = URLSession(configuration: .default, delegate: DDPClientURLSessionChallengeDelegate(), delegateQueue: nil)
5047
let task = session.webSocketTask(with: url)
51-
52-
self.urlSessionChallengeDelegate = challengeDelegate
48+
5349
self.urlSession = session
5450
self.webSocketTask = task
5551
self.isConnected = false
@@ -171,7 +167,6 @@ final class DDPClient {
171167
webSocketTask = nil
172168
urlSession?.invalidateAndCancel()
173169
urlSession = nil
174-
urlSessionChallengeDelegate = nil
175170
}
176171

177172
// MARK: - Private
@@ -410,18 +405,9 @@ final class DDPClient {
410405

411406
/// Forwards URL authentication challenges to the existing `Challenge` implementation in `SSLPinning.mm`
412407
/// (same path as `RCTHTTPRequestHandler` swizzling) so WebSocket TLS uses the same client-certificate flow.
413-
private final class DDPClientURLSessionChallengeDelegate: NSObject, URLSessionDelegate, URLSessionTaskDelegate {
414-
func urlSession(
415-
_ session: URLSession,
416-
didReceive challenge: URLAuthenticationChallenge,
417-
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
418-
) {
419-
Challenge.runChallenge(session, didReceiveChallenge: challenge, completionHandler: completionHandler)
420-
}
421-
408+
private final class DDPClientURLSessionChallengeDelegate: NSObject, URLSessionDelegate {
422409
func urlSession(
423410
_ session: URLSession,
424-
task: URLSessionTask,
425411
didReceive challenge: URLAuthenticationChallenge,
426412
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
427413
) {

0 commit comments

Comments
 (0)