@@ -76,7 +76,9 @@ public protocol URLSessionDelegate : NSObjectProtocol, Sendable {
7676
7777extension URLSessionDelegate {
7878 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+ }
8082}
8183
8284/* If an application has received an
@@ -244,15 +246,27 @@ public protocol URLSessionDataDelegate : URLSessionTaskDelegate {
244246
245247extension URLSessionDataDelegate {
246248
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+ }
248256
249257 public func urlSession( _ session: URLSession , dataTask: URLSessionDataTask , didBecome downloadTask: URLSessionDownloadTask ) { }
250258
251259 public func urlSession( _ session: URLSession , dataTask: URLSessionDataTask , didBecome streamTask: URLSessionStreamTask ) { }
252260
253261 public func urlSession( _ session: URLSession , dataTask: URLSessionDataTask , didReceive data: Data ) { }
254262
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+ }
256270}
257271
258272/*
0 commit comments