forked from loafle/openapi-generator-original
[swift6] simplify authentication (#19839)
This commit is contained in:
parent
715f6b634e
commit
185c0639c0
@ -52,8 +52,6 @@ extension URLSessionDataTask: URLSessionDataTaskProtocol {}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} typealias {{projectName}}APIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
|
||||||
|
|
||||||
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
||||||
private init() {
|
private init() {
|
||||||
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||||
@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
// Store the URLSession to retain its reference
|
// Store the URLSession to retain its reference
|
||||||
let defaultURLSession: URLSession
|
let defaultURLSession: URLSession
|
||||||
|
|
||||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
|
||||||
var challengeHandlerStore = SynchronizedDictionary<Int, {{projectName}}APIChallengeHandler>()
|
|
||||||
|
|
||||||
// Store current URLCredential for every URLSessionTask
|
// Store current URLCredential for every URLSessionTask
|
||||||
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
||||||
|
|
||||||
/**
|
|
||||||
May be assigned if you want to control the authentication challenges.
|
|
||||||
*/
|
|
||||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var taskDidReceiveChallenge: {{projectName}}APIChallengeHandler?
|
|
||||||
|
|
||||||
required {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
required {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
||||||
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
||||||
}
|
}
|
||||||
@ -187,7 +177,6 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
|
|
||||||
self.onProgressReady?(dataTask.progress)
|
self.onProgressReady?(dataTask.progress)
|
||||||
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
||||||
|
|
||||||
self.requestTask.set(task: dataTask)
|
self.requestTask.set(task: dataTask)
|
||||||
@ -211,7 +200,6 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
|
|
||||||
private func cleanupRequest() {
|
private func cleanupRequest() {
|
||||||
if let task = requestTask.get() {
|
if let task = requestTask.get() {
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,9 +396,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
|
|
||||||
var credential: URLCredential?
|
var credential: URLCredential?
|
||||||
|
|
||||||
if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
|
|
||||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
|
||||||
} else {
|
|
||||||
if challenge.previousFailureCount > 0 {
|
if challenge.previousFailureCount > 0 {
|
||||||
disposition = .rejectProtectionSpace
|
disposition = .rejectProtectionSpace
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +405,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
disposition = .useCredential
|
disposition = .useCredential
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(disposition, credential)
|
completionHandler(disposition, credential)
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
|
||||||
|
|
||||||
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
||||||
private init() {
|
private init() {
|
||||||
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||||
@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
// Store the URLSession to retain its reference
|
// Store the URLSession to retain its reference
|
||||||
let defaultURLSession: URLSession
|
let defaultURLSession: URLSession
|
||||||
|
|
||||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
|
||||||
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()
|
|
||||||
|
|
||||||
// Store current URLCredential for every URLSessionTask
|
// Store current URLCredential for every URLSessionTask
|
||||||
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||||
}
|
}
|
||||||
|
|
||||||
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
||||||
|
|
||||||
/**
|
|
||||||
May be assigned if you want to control the authentication challenges.
|
|
||||||
*/
|
|
||||||
public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler?
|
|
||||||
|
|
||||||
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
||||||
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
||||||
}
|
}
|
||||||
@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
self.onProgressReady?(dataTask.progress)
|
self.onProgressReady?(dataTask.progress)
|
||||||
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
||||||
|
|
||||||
self.requestTask.set(task: dataTask)
|
self.requestTask.set(task: dataTask)
|
||||||
@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
private func cleanupRequest() {
|
private func cleanupRequest() {
|
||||||
if let task = requestTask.get() {
|
if let task = requestTask.get() {
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,9 +396,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
|
|
||||||
var credential: URLCredential?
|
var credential: URLCredential?
|
||||||
|
|
||||||
if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
|
|
||||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
|
||||||
} else {
|
|
||||||
if challenge.previousFailureCount > 0 {
|
if challenge.previousFailureCount > 0 {
|
||||||
disposition = .rejectProtectionSpace
|
disposition = .rejectProtectionSpace
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +405,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
disposition = .useCredential
|
disposition = .useCredential
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(disposition, credential)
|
completionHandler(disposition, credential)
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
|
||||||
|
|
||||||
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
||||||
private init() {
|
private init() {
|
||||||
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||||
@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
// Store the URLSession to retain its reference
|
// Store the URLSession to retain its reference
|
||||||
let defaultURLSession: URLSession
|
let defaultURLSession: URLSession
|
||||||
|
|
||||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
|
||||||
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()
|
|
||||||
|
|
||||||
// Store current URLCredential for every URLSessionTask
|
// Store current URLCredential for every URLSessionTask
|
||||||
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||||
}
|
}
|
||||||
|
|
||||||
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
||||||
|
|
||||||
/**
|
|
||||||
May be assigned if you want to control the authentication challenges.
|
|
||||||
*/
|
|
||||||
public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler?
|
|
||||||
|
|
||||||
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
||||||
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
||||||
}
|
}
|
||||||
@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
self.onProgressReady?(dataTask.progress)
|
self.onProgressReady?(dataTask.progress)
|
||||||
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
||||||
|
|
||||||
self.requestTask.set(task: dataTask)
|
self.requestTask.set(task: dataTask)
|
||||||
@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
private func cleanupRequest() {
|
private func cleanupRequest() {
|
||||||
if let task = requestTask.get() {
|
if let task = requestTask.get() {
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,9 +396,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
|
|
||||||
var credential: URLCredential?
|
var credential: URLCredential?
|
||||||
|
|
||||||
if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
|
|
||||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
|
||||||
} else {
|
|
||||||
if challenge.previousFailureCount > 0 {
|
if challenge.previousFailureCount > 0 {
|
||||||
disposition = .rejectProtectionSpace
|
disposition = .rejectProtectionSpace
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +405,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
disposition = .useCredential
|
disposition = .useCredential
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(disposition, credential)
|
completionHandler(disposition, credential)
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
|
||||||
|
|
||||||
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
||||||
private init() {
|
private init() {
|
||||||
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||||
@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
// Store the URLSession to retain its reference
|
// Store the URLSession to retain its reference
|
||||||
let defaultURLSession: URLSession
|
let defaultURLSession: URLSession
|
||||||
|
|
||||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
|
||||||
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()
|
|
||||||
|
|
||||||
// Store current URLCredential for every URLSessionTask
|
// Store current URLCredential for every URLSessionTask
|
||||||
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||||
}
|
}
|
||||||
|
|
||||||
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
||||||
|
|
||||||
/**
|
|
||||||
May be assigned if you want to control the authentication challenges.
|
|
||||||
*/
|
|
||||||
public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler?
|
|
||||||
|
|
||||||
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
||||||
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
||||||
}
|
}
|
||||||
@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
self.onProgressReady?(dataTask.progress)
|
self.onProgressReady?(dataTask.progress)
|
||||||
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
||||||
|
|
||||||
self.requestTask.set(task: dataTask)
|
self.requestTask.set(task: dataTask)
|
||||||
@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
private func cleanupRequest() {
|
private func cleanupRequest() {
|
||||||
if let task = requestTask.get() {
|
if let task = requestTask.get() {
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,9 +396,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
|
|
||||||
var credential: URLCredential?
|
var credential: URLCredential?
|
||||||
|
|
||||||
if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
|
|
||||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
|
||||||
} else {
|
|
||||||
if challenge.previousFailureCount > 0 {
|
if challenge.previousFailureCount > 0 {
|
||||||
disposition = .rejectProtectionSpace
|
disposition = .rejectProtectionSpace
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +405,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
disposition = .useCredential
|
disposition = .useCredential
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(disposition, credential)
|
completionHandler(disposition, credential)
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
|
||||||
|
|
||||||
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
||||||
private init() {
|
private init() {
|
||||||
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||||
@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
// Store the URLSession to retain its reference
|
// Store the URLSession to retain its reference
|
||||||
let defaultURLSession: URLSession
|
let defaultURLSession: URLSession
|
||||||
|
|
||||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
|
||||||
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()
|
|
||||||
|
|
||||||
// Store current URLCredential for every URLSessionTask
|
// Store current URLCredential for every URLSessionTask
|
||||||
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||||
}
|
}
|
||||||
|
|
||||||
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
||||||
|
|
||||||
/**
|
|
||||||
May be assigned if you want to control the authentication challenges.
|
|
||||||
*/
|
|
||||||
public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler?
|
|
||||||
|
|
||||||
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
||||||
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
||||||
}
|
}
|
||||||
@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
self.onProgressReady?(dataTask.progress)
|
self.onProgressReady?(dataTask.progress)
|
||||||
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
||||||
|
|
||||||
self.requestTask.set(task: dataTask)
|
self.requestTask.set(task: dataTask)
|
||||||
@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
private func cleanupRequest() {
|
private func cleanupRequest() {
|
||||||
if let task = requestTask.get() {
|
if let task = requestTask.get() {
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,9 +396,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
|
|
||||||
var credential: URLCredential?
|
var credential: URLCredential?
|
||||||
|
|
||||||
if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
|
|
||||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
|
||||||
} else {
|
|
||||||
if challenge.previousFailureCount > 0 {
|
if challenge.previousFailureCount > 0 {
|
||||||
disposition = .rejectProtectionSpace
|
disposition = .rejectProtectionSpace
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +405,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
disposition = .useCredential
|
disposition = .useCredential
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(disposition, credential)
|
completionHandler(disposition, credential)
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
|
||||||
|
|
||||||
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
||||||
private init() {
|
private init() {
|
||||||
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||||
@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
// Store the URLSession to retain its reference
|
// Store the URLSession to retain its reference
|
||||||
let defaultURLSession: URLSession
|
let defaultURLSession: URLSession
|
||||||
|
|
||||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
|
||||||
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()
|
|
||||||
|
|
||||||
// Store current URLCredential for every URLSessionTask
|
// Store current URLCredential for every URLSessionTask
|
||||||
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||||
}
|
}
|
||||||
|
|
||||||
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
||||||
|
|
||||||
/**
|
|
||||||
May be assigned if you want to control the authentication challenges.
|
|
||||||
*/
|
|
||||||
public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler?
|
|
||||||
|
|
||||||
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
||||||
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
||||||
}
|
}
|
||||||
@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
self.onProgressReady?(dataTask.progress)
|
self.onProgressReady?(dataTask.progress)
|
||||||
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
||||||
|
|
||||||
self.requestTask.set(task: dataTask)
|
self.requestTask.set(task: dataTask)
|
||||||
@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
private func cleanupRequest() {
|
private func cleanupRequest() {
|
||||||
if let task = requestTask.get() {
|
if let task = requestTask.get() {
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,9 +396,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
|
|
||||||
var credential: URLCredential?
|
var credential: URLCredential?
|
||||||
|
|
||||||
if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
|
|
||||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
|
||||||
} else {
|
|
||||||
if challenge.previousFailureCount > 0 {
|
if challenge.previousFailureCount > 0 {
|
||||||
disposition = .rejectProtectionSpace
|
disposition = .rejectProtectionSpace
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +405,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
disposition = .useCredential
|
disposition = .useCredential
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(disposition, credential)
|
completionHandler(disposition, credential)
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
|
||||||
|
|
||||||
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
||||||
private init() {
|
private init() {
|
||||||
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||||
@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
// Store the URLSession to retain its reference
|
// Store the URLSession to retain its reference
|
||||||
let defaultURLSession: URLSession
|
let defaultURLSession: URLSession
|
||||||
|
|
||||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
|
||||||
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()
|
|
||||||
|
|
||||||
// Store current URLCredential for every URLSessionTask
|
// Store current URLCredential for every URLSessionTask
|
||||||
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||||
}
|
}
|
||||||
|
|
||||||
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
||||||
|
|
||||||
/**
|
|
||||||
May be assigned if you want to control the authentication challenges.
|
|
||||||
*/
|
|
||||||
public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler?
|
|
||||||
|
|
||||||
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
||||||
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
||||||
}
|
}
|
||||||
@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
self.onProgressReady?(dataTask.progress)
|
self.onProgressReady?(dataTask.progress)
|
||||||
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
||||||
|
|
||||||
self.requestTask.set(task: dataTask)
|
self.requestTask.set(task: dataTask)
|
||||||
@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
private func cleanupRequest() {
|
private func cleanupRequest() {
|
||||||
if let task = requestTask.get() {
|
if let task = requestTask.get() {
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,9 +396,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
|
|
||||||
var credential: URLCredential?
|
var credential: URLCredential?
|
||||||
|
|
||||||
if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
|
|
||||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
|
||||||
} else {
|
|
||||||
if challenge.previousFailureCount > 0 {
|
if challenge.previousFailureCount > 0 {
|
||||||
disposition = .rejectProtectionSpace
|
disposition = .rejectProtectionSpace
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +405,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
disposition = .useCredential
|
disposition = .useCredential
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(disposition, credential)
|
completionHandler(disposition, credential)
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
|
||||||
|
|
||||||
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
||||||
private init() {
|
private init() {
|
||||||
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||||
@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
// Store the URLSession to retain its reference
|
// Store the URLSession to retain its reference
|
||||||
let defaultURLSession: URLSession
|
let defaultURLSession: URLSession
|
||||||
|
|
||||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
|
||||||
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()
|
|
||||||
|
|
||||||
// Store current URLCredential for every URLSessionTask
|
// Store current URLCredential for every URLSessionTask
|
||||||
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||||
}
|
}
|
||||||
|
|
||||||
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
||||||
|
|
||||||
/**
|
|
||||||
May be assigned if you want to control the authentication challenges.
|
|
||||||
*/
|
|
||||||
public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler?
|
|
||||||
|
|
||||||
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
||||||
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
||||||
}
|
}
|
||||||
@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
self.onProgressReady?(dataTask.progress)
|
self.onProgressReady?(dataTask.progress)
|
||||||
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
||||||
|
|
||||||
self.requestTask.set(task: dataTask)
|
self.requestTask.set(task: dataTask)
|
||||||
@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
private func cleanupRequest() {
|
private func cleanupRequest() {
|
||||||
if let task = requestTask.get() {
|
if let task = requestTask.get() {
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,9 +396,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
|
|
||||||
var credential: URLCredential?
|
var credential: URLCredential?
|
||||||
|
|
||||||
if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
|
|
||||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
|
||||||
} else {
|
|
||||||
if challenge.previousFailureCount > 0 {
|
if challenge.previousFailureCount > 0 {
|
||||||
disposition = .rejectProtectionSpace
|
disposition = .rejectProtectionSpace
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +405,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
disposition = .useCredential
|
disposition = .useCredential
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(disposition, credential)
|
completionHandler(disposition, credential)
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,6 @@ internal class URLSessionRequestBuilderFactory: RequestBuilderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
|
||||||
|
|
||||||
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
||||||
private init() {
|
private init() {
|
||||||
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||||
@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
// Store the URLSession to retain its reference
|
// Store the URLSession to retain its reference
|
||||||
let defaultURLSession: URLSession
|
let defaultURLSession: URLSession
|
||||||
|
|
||||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
|
||||||
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()
|
|
||||||
|
|
||||||
// Store current URLCredential for every URLSessionTask
|
// Store current URLCredential for every URLSessionTask
|
||||||
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
internal class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
||||||
|
|
||||||
/**
|
|
||||||
May be assigned if you want to control the authentication challenges.
|
|
||||||
*/
|
|
||||||
internal var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler?
|
|
||||||
|
|
||||||
required internal init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
required internal init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
||||||
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
||||||
}
|
}
|
||||||
@ -187,7 +177,6 @@ internal class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendab
|
|||||||
|
|
||||||
self.onProgressReady?(dataTask.progress)
|
self.onProgressReady?(dataTask.progress)
|
||||||
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
||||||
|
|
||||||
self.requestTask.set(task: dataTask)
|
self.requestTask.set(task: dataTask)
|
||||||
@ -211,7 +200,6 @@ internal class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendab
|
|||||||
|
|
||||||
private func cleanupRequest() {
|
private func cleanupRequest() {
|
||||||
if let task = requestTask.get() {
|
if let task = requestTask.get() {
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,9 +396,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
|
|
||||||
var credential: URLCredential?
|
var credential: URLCredential?
|
||||||
|
|
||||||
if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
|
|
||||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
|
||||||
} else {
|
|
||||||
if challenge.previousFailureCount > 0 {
|
if challenge.previousFailureCount > 0 {
|
||||||
disposition = .rejectProtectionSpace
|
disposition = .rejectProtectionSpace
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +405,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
disposition = .useCredential
|
disposition = .useCredential
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(disposition, credential)
|
completionHandler(disposition, credential)
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
|
||||||
|
|
||||||
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
||||||
private init() {
|
private init() {
|
||||||
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||||
@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
// Store the URLSession to retain its reference
|
// Store the URLSession to retain its reference
|
||||||
let defaultURLSession: URLSession
|
let defaultURLSession: URLSession
|
||||||
|
|
||||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
|
||||||
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()
|
|
||||||
|
|
||||||
// Store current URLCredential for every URLSessionTask
|
// Store current URLCredential for every URLSessionTask
|
||||||
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||||
}
|
}
|
||||||
|
|
||||||
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
||||||
|
|
||||||
/**
|
|
||||||
May be assigned if you want to control the authentication challenges.
|
|
||||||
*/
|
|
||||||
public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler?
|
|
||||||
|
|
||||||
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
||||||
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
||||||
}
|
}
|
||||||
@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
self.onProgressReady?(dataTask.progress)
|
self.onProgressReady?(dataTask.progress)
|
||||||
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
||||||
|
|
||||||
self.requestTask.set(task: dataTask)
|
self.requestTask.set(task: dataTask)
|
||||||
@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
private func cleanupRequest() {
|
private func cleanupRequest() {
|
||||||
if let task = requestTask.get() {
|
if let task = requestTask.get() {
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,9 +396,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
|
|
||||||
var credential: URLCredential?
|
var credential: URLCredential?
|
||||||
|
|
||||||
if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
|
|
||||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
|
||||||
} else {
|
|
||||||
if challenge.previousFailureCount > 0 {
|
if challenge.previousFailureCount > 0 {
|
||||||
disposition = .rejectProtectionSpace
|
disposition = .rejectProtectionSpace
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +405,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
disposition = .useCredential
|
disposition = .useCredential
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(disposition, credential)
|
completionHandler(disposition, credential)
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
|
||||||
|
|
||||||
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
||||||
private init() {
|
private init() {
|
||||||
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||||
@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
// Store the URLSession to retain its reference
|
// Store the URLSession to retain its reference
|
||||||
let defaultURLSession: URLSession
|
let defaultURLSession: URLSession
|
||||||
|
|
||||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
|
||||||
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()
|
|
||||||
|
|
||||||
// Store current URLCredential for every URLSessionTask
|
// Store current URLCredential for every URLSessionTask
|
||||||
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||||
}
|
}
|
||||||
|
|
||||||
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
||||||
|
|
||||||
/**
|
|
||||||
May be assigned if you want to control the authentication challenges.
|
|
||||||
*/
|
|
||||||
public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler?
|
|
||||||
|
|
||||||
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
||||||
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
||||||
}
|
}
|
||||||
@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
self.onProgressReady?(dataTask.progress)
|
self.onProgressReady?(dataTask.progress)
|
||||||
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
||||||
|
|
||||||
self.requestTask.set(task: dataTask)
|
self.requestTask.set(task: dataTask)
|
||||||
@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
private func cleanupRequest() {
|
private func cleanupRequest() {
|
||||||
if let task = requestTask.get() {
|
if let task = requestTask.get() {
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,9 +396,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
|
|
||||||
var credential: URLCredential?
|
var credential: URLCredential?
|
||||||
|
|
||||||
if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
|
|
||||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
|
||||||
} else {
|
|
||||||
if challenge.previousFailureCount > 0 {
|
if challenge.previousFailureCount > 0 {
|
||||||
disposition = .rejectProtectionSpace
|
disposition = .rejectProtectionSpace
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +405,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
disposition = .useCredential
|
disposition = .useCredential
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(disposition, credential)
|
completionHandler(disposition, credential)
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
|
||||||
|
|
||||||
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
||||||
private init() {
|
private init() {
|
||||||
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||||
@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
|
|||||||
// Store the URLSession to retain its reference
|
// Store the URLSession to retain its reference
|
||||||
let defaultURLSession: URLSession
|
let defaultURLSession: URLSession
|
||||||
|
|
||||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
|
||||||
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()
|
|
||||||
|
|
||||||
// Store current URLCredential for every URLSessionTask
|
// Store current URLCredential for every URLSessionTask
|
||||||
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||||
}
|
}
|
||||||
|
|
||||||
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
||||||
|
|
||||||
/**
|
|
||||||
May be assigned if you want to control the authentication challenges.
|
|
||||||
*/
|
|
||||||
public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler?
|
|
||||||
|
|
||||||
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool, openAPIClient: OpenAPIClient = OpenAPIClient.shared) {
|
||||||
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
|
||||||
}
|
}
|
||||||
@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
self.onProgressReady?(dataTask.progress)
|
self.onProgressReady?(dataTask.progress)
|
||||||
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential
|
||||||
|
|
||||||
self.requestTask.set(task: dataTask)
|
self.requestTask.set(task: dataTask)
|
||||||
@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {
|
|||||||
|
|
||||||
private func cleanupRequest() {
|
private func cleanupRequest() {
|
||||||
if let task = requestTask.get() {
|
if let task = requestTask.get() {
|
||||||
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
|
|
||||||
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,9 +396,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
|
|
||||||
var credential: URLCredential?
|
var credential: URLCredential?
|
||||||
|
|
||||||
if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
|
|
||||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
|
||||||
} else {
|
|
||||||
if challenge.previousFailureCount > 0 {
|
if challenge.previousFailureCount > 0 {
|
||||||
disposition = .rejectProtectionSpace
|
disposition = .rejectProtectionSpace
|
||||||
} else {
|
} else {
|
||||||
@ -420,7 +405,6 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
|||||||
disposition = .useCredential
|
disposition = .useCredential
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(disposition, credential)
|
completionHandler(disposition, credential)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user