Skip to content

Commit 4360a00

Browse files
committed
Fix authentication through the session task delegate (SR-12676)
- WWW-Authenticate must canonicalize with 'WWW' uppercase. - The session delegate must be consulted for authentication even for tasks that have completion blocks. https://bugs.swift.org/browse/SR-12676
1 parent ca6cda5 commit 4360a00

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Sources/FoundationNetworking/URLResponse.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ open class HTTPURLResponse : URLResponse {
197197
if key.isEmpty { continue }
198198
if key.hasPrefix("x-") || key.hasPrefix("X-") {
199199
canonicalizedFields[key] = value
200+
} else if key.caseInsensitiveCompare("WWW-Authenticate") == .orderedSame {
201+
canonicalizedFields["WWW-Authenticate"] = value
200202
} else {
201203
canonicalizedFields[key.capitalized] = value
202204
}

Sources/FoundationNetworking/URLSession/URLSessionTask.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,7 @@ extension _ProtocolClient : URLProtocolClient {
950950
}
951951
}
952952

953-
switch session.behaviour(for: task) {
954-
case .taskDelegate(let delegate):
953+
if let delegate = session.delegate as? URLSessionTaskDelegate {
955954
session.delegateQueue.addOperation {
956955
delegate.urlSession(session, task: task, didReceive: challenge) { disposition, credential in
957956

@@ -971,7 +970,7 @@ extension _ProtocolClient : URLProtocolClient {
971970

972971
}
973972
}
974-
default:
973+
} else {
975974
attemptProceedingWithDefaultCredential()
976975
}
977976
}

0 commit comments

Comments
 (0)