mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
41 lines
1.0 KiB
Swift
41 lines
1.0 KiB
Swift
// Copyright 2022 Yandex LLC. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
final class AuthChallengeHandler: ChallengeHandling {
|
|
private let nextHandler: ChallengeHandling?
|
|
private let trustedHosts: [String]
|
|
private let request: URLRequest
|
|
|
|
init(
|
|
nextHandler: ChallengeHandling?,
|
|
trustedHosts: [String],
|
|
request: URLRequest
|
|
) {
|
|
self.nextHandler = nextHandler
|
|
self.trustedHosts = trustedHosts
|
|
self.request = request
|
|
}
|
|
|
|
func handleChallenge(
|
|
with protectionSpace: URLProtectionSpace,
|
|
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
|
|
) {
|
|
#if INTERNAL_BUILD
|
|
if let host = request.url?.host, trustedHosts.contains(host) {
|
|
completionHandler(.useCredential, URLCredential(trust: protectionSpace.serverTrust!))
|
|
return
|
|
}
|
|
#endif
|
|
|
|
if let nextHandler = nextHandler {
|
|
nextHandler.handleChallenge(
|
|
with: protectionSpace,
|
|
completionHandler: completionHandler
|
|
)
|
|
} else {
|
|
completionHandler(.performDefaultHandling, nil)
|
|
}
|
|
}
|
|
}
|