Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
private init() {
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
Expand All @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
// Store the URLSession to retain its reference
let defaultURLSession: URLSession

// Store current taskDidReceiveChallenge for every URLSessionTask
var challengeHandlerStore = SynchronizedDictionary<Int, {{projectName}}APIChallengeHandler>()

// Store current URLCredential for every URLSessionTask
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
}

{{#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) {
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
}
Expand Down Expand Up @@ -187,7 +177,6 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {

self.onProgressReady?(dataTask.progress)

URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential

self.requestTask.set(task: dataTask)
Expand All @@ -211,7 +200,6 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {

private func cleanupRequest() {
if let task = requestTask.get() {
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
}
}
Expand Down Expand Up @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {

var credential: URLCredential?

if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
if challenge.previousFailureCount > 0 {
disposition = .rejectProtectionSpace
} else {
if challenge.previousFailureCount > 0 {
disposition = .rejectProtectionSpace
} else {
credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)
credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)

if credential != nil {
disposition = .useCredential
}
if credential != nil {
disposition = .useCredential
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
}
}

public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))

fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
private init() {
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
Expand All @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
// Store the URLSession to retain its reference
let defaultURLSession: URLSession

// Store current taskDidReceiveChallenge for every URLSessionTask
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()

// Store current URLCredential for every URLSessionTask
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
}

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) {
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
}
Expand Down Expand Up @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {

self.onProgressReady?(dataTask.progress)

URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential

self.requestTask.set(task: dataTask)
Expand All @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {

private func cleanupRequest() {
if let task = requestTask.get() {
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
}
}
Expand Down Expand Up @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {

var credential: URLCredential?

if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
if challenge.previousFailureCount > 0 {
disposition = .rejectProtectionSpace
} else {
if challenge.previousFailureCount > 0 {
disposition = .rejectProtectionSpace
} else {
credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)
credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)

if credential != nil {
disposition = .useCredential
}
if credential != nil {
disposition = .useCredential
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
}
}

public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))

fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
private init() {
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
Expand All @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
// Store the URLSession to retain its reference
let defaultURLSession: URLSession

// Store current taskDidReceiveChallenge for every URLSessionTask
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()

// Store current URLCredential for every URLSessionTask
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
}

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) {
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
}
Expand Down Expand Up @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {

self.onProgressReady?(dataTask.progress)

URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential

self.requestTask.set(task: dataTask)
Expand All @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {

private func cleanupRequest() {
if let task = requestTask.get() {
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
}
}
Expand Down Expand Up @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {

var credential: URLCredential?

if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
if challenge.previousFailureCount > 0 {
disposition = .rejectProtectionSpace
} else {
if challenge.previousFailureCount > 0 {
disposition = .rejectProtectionSpace
} else {
credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)
credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)

if credential != nil {
disposition = .useCredential
}
if credential != nil {
disposition = .useCredential
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
}
}

public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))

fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
private init() {
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
Expand All @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
// Store the URLSession to retain its reference
let defaultURLSession: URLSession

// Store current taskDidReceiveChallenge for every URLSessionTask
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()

// Store current URLCredential for every URLSessionTask
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
}

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) {
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
}
Expand Down Expand Up @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {

self.onProgressReady?(dataTask.progress)

URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential

self.requestTask.set(task: dataTask)
Expand All @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {

private func cleanupRequest() {
if let task = requestTask.get() {
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
}
}
Expand Down Expand Up @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {

var credential: URLCredential?

if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
if challenge.previousFailureCount > 0 {
disposition = .rejectProtectionSpace
} else {
if challenge.previousFailureCount > 0 {
disposition = .rejectProtectionSpace
} else {
credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)
credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)

if credential != nil {
disposition = .useCredential
}
if credential != nil {
disposition = .useCredential
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public class URLSessionRequestBuilderFactory: RequestBuilderFactory {
}
}

public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))

fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
private init() {
defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
Expand All @@ -67,20 +65,12 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
// Store the URLSession to retain its reference
let defaultURLSession: URLSession

// Store current taskDidReceiveChallenge for every URLSessionTask
var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()

// Store current URLCredential for every URLSessionTask
var credentialStore = SynchronizedDictionary<Int, URLCredential>()
}

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) {
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication, openAPIClient: openAPIClient)
}
Expand Down Expand Up @@ -187,7 +177,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {

self.onProgressReady?(dataTask.progress)

URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[dataTask.taskIdentifier] = self.taskDidReceiveChallenge
URLSessionRequestBuilderConfiguration.shared.credentialStore[dataTask.taskIdentifier] = self.credential

self.requestTask.set(task: dataTask)
Expand All @@ -211,7 +200,6 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T>, @unchecked Sendable {

private func cleanupRequest() {
if let task = requestTask.get() {
URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] = nil
URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] = nil
}
}
Expand Down Expand Up @@ -408,17 +396,13 @@ fileprivate final class SessionDelegate: NSObject, URLSessionTaskDelegate {

var credential: URLCredential?

if let taskDidReceiveChallenge = URLSessionRequestBuilderConfiguration.shared.challengeHandlerStore[task.taskIdentifier] {
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
if challenge.previousFailureCount > 0 {
disposition = .rejectProtectionSpace
} else {
if challenge.previousFailureCount > 0 {
disposition = .rejectProtectionSpace
} else {
credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)
credential = URLSessionRequestBuilderConfiguration.shared.credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)

if credential != nil {
disposition = .useCredential
}
if credential != nil {
disposition = .useCredential
}
}

Expand Down
Loading