Skip to content

Commit 37628a1

Browse files
Fix for URLSession registers native protocol classes for each new session
1 parent bdd4cef commit 37628a1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Foundation/NSURLSession/NSURLSession.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ open class URLSession : NSObject {
191191
internal let taskRegistry = URLSession._TaskRegistry()
192192
fileprivate let identifier: Int32
193193
fileprivate var invalidated = false
194+
fileprivate static let registerProtocols = {
195+
// TODO: We register all the native protocols here.
196+
let _ = URLProtocol.registerClass(_HTTPURLProtocol.self)
197+
}()
194198

195199
/*
196200
* The shared session uses the currently set global NSURLCache,
@@ -221,7 +225,7 @@ open class URLSession : NSObject {
221225
self._configuration = c
222226
self.multiHandle = _MultiHandle(configuration: c, workQueue: workQueue)
223227
// registering all the protocol classes with URLProtocol
224-
let _ = URLProtocol.registerClass(_HTTPURLProtocol.self)
228+
let _ = URLSession.registerProtocols
225229
}
226230

227231
/*
@@ -248,7 +252,7 @@ open class URLSession : NSObject {
248252
self._configuration = c
249253
self.multiHandle = _MultiHandle(configuration: c, workQueue: workQueue)
250254
// registering all the protocol classes with URLProtocol
251-
let _ = URLProtocol.registerClass(_HTTPURLProtocol.self)
255+
let _ = URLSession.registerProtocols
252256
}
253257

254258
open let delegateQueue: OperationQueue

0 commit comments

Comments
 (0)