@@ -76,7 +76,9 @@ public protocol URLSessionDelegate : NSObjectProtocol, Sendable {
76
76
77
77
extension URLSessionDelegate {
78
78
public func urlSession( _ session: URLSession , didBecomeInvalidWithError error: Error ? ) { }
79
- public func urlSession( _ session: URLSession , didReceive challenge: URLAuthenticationChallenge , completionHandler: @Sendable @escaping ( URLSession . AuthChallengeDisposition , URLCredential ? ) -> Void ) { }
79
+ public func urlSession( _ session: URLSession , didReceive challenge: URLAuthenticationChallenge , completionHandler: @Sendable @escaping ( URLSession . AuthChallengeDisposition , URLCredential ? ) -> Void ) {
80
+ completionHandler ( . performDefaultHandling, nil )
81
+ }
80
82
}
81
83
82
84
/* If an application has received an
@@ -244,15 +246,27 @@ public protocol URLSessionDataDelegate : URLSessionTaskDelegate {
244
246
245
247
extension URLSessionDataDelegate {
246
248
247
- public func urlSession( _ session: URLSession , dataTask: URLSessionDataTask , didReceive response: URLResponse , completionHandler: @Sendable @escaping ( URLSession . ResponseDisposition ) -> Void ) { }
249
+ public func urlSession( _ session: URLSession , dataTask: URLSessionDataTask , didReceive response: URLResponse , completionHandler: @Sendable @escaping ( URLSession . ResponseDisposition ) -> Void ) {
250
+ if self === dataTask. delegate, let sessionDelegate = session. delegate as? URLSessionDataDelegate , self !== sessionDelegate {
251
+ sessionDelegate. urlSession ( session, dataTask: dataTask, didReceive: response, completionHandler: completionHandler)
252
+ } else {
253
+ completionHandler ( . allow)
254
+ }
255
+ }
248
256
249
257
public func urlSession( _ session: URLSession , dataTask: URLSessionDataTask , didBecome downloadTask: URLSessionDownloadTask ) { }
250
258
251
259
public func urlSession( _ session: URLSession , dataTask: URLSessionDataTask , didBecome streamTask: URLSessionStreamTask ) { }
252
260
253
261
public func urlSession( _ session: URLSession , dataTask: URLSessionDataTask , didReceive data: Data ) { }
254
262
255
- public func urlSession( _ session: URLSession , dataTask: URLSessionDataTask , willCacheResponse proposedResponse: CachedURLResponse , completionHandler: @Sendable @escaping ( CachedURLResponse ? ) -> Void ) { }
263
+ public func urlSession( _ session: URLSession , dataTask: URLSessionDataTask , willCacheResponse proposedResponse: CachedURLResponse , completionHandler: @Sendable @escaping ( CachedURLResponse ? ) -> Void ) {
264
+ if self === dataTask. delegate, let sessionDelegate = session. delegate as? URLSessionDataDelegate , self !== sessionDelegate {
265
+ sessionDelegate. urlSession ( session, dataTask: dataTask, willCacheResponse: proposedResponse, completionHandler: completionHandler)
266
+ } else {
267
+ completionHandler ( proposedResponse)
268
+ }
269
+ }
256
270
}
257
271
258
272
/*
0 commit comments