|
|
@@ -127,7 +127,7 @@ public class Request {
|
|
|
fileprivate var mutableState = MutableState()
|
|
|
|
|
|
/// `State` of the `Request`.
|
|
|
- public var state: State { mutableState.state }
|
|
|
+ public var state: State { $mutableState.state }
|
|
|
/// Returns whether `state` is `.initialized`.
|
|
|
public var isInitialized: Bool { state == .initialized }
|
|
|
/// Returns whether `state is `.resumed`.
|
|
|
@@ -150,38 +150,38 @@ public class Request {
|
|
|
public let downloadProgress = Progress(totalUnitCount: 0)
|
|
|
/// `ProgressHandler` called when `uploadProgress` is updated, on the provided `DispatchQueue`.
|
|
|
private var uploadProgressHandler: (handler: ProgressHandler, queue: DispatchQueue)? {
|
|
|
- get { mutableState.uploadProgressHandler }
|
|
|
- set { mutableState.uploadProgressHandler = newValue }
|
|
|
+ get { $mutableState.uploadProgressHandler }
|
|
|
+ set { $mutableState.uploadProgressHandler = newValue }
|
|
|
}
|
|
|
|
|
|
/// `ProgressHandler` called when `downloadProgress` is updated, on the provided `DispatchQueue`.
|
|
|
fileprivate var downloadProgressHandler: (handler: ProgressHandler, queue: DispatchQueue)? {
|
|
|
- get { mutableState.downloadProgressHandler }
|
|
|
- set { mutableState.downloadProgressHandler = newValue }
|
|
|
+ get { $mutableState.downloadProgressHandler }
|
|
|
+ set { $mutableState.downloadProgressHandler = newValue }
|
|
|
}
|
|
|
|
|
|
// MARK: Redirect Handling
|
|
|
|
|
|
/// `RedirectHandler` set on the instance.
|
|
|
public private(set) var redirectHandler: RedirectHandler? {
|
|
|
- get { mutableState.redirectHandler }
|
|
|
- set { mutableState.redirectHandler = newValue }
|
|
|
+ get { $mutableState.redirectHandler }
|
|
|
+ set { $mutableState.redirectHandler = newValue }
|
|
|
}
|
|
|
|
|
|
// MARK: Cached Response Handling
|
|
|
|
|
|
/// `CachedResponseHandler` set on the instance.
|
|
|
public private(set) var cachedResponseHandler: CachedResponseHandler? {
|
|
|
- get { mutableState.cachedResponseHandler }
|
|
|
- set { mutableState.cachedResponseHandler = newValue }
|
|
|
+ get { $mutableState.cachedResponseHandler }
|
|
|
+ set { $mutableState.cachedResponseHandler = newValue }
|
|
|
}
|
|
|
|
|
|
// MARK: URLCredential
|
|
|
|
|
|
/// `URLCredential` used for authentication challenges. Created by calling one of the `authenticate` methods.
|
|
|
public private(set) var credential: URLCredential? {
|
|
|
- get { mutableState.credential }
|
|
|
- set { mutableState.credential = newValue }
|
|
|
+ get { $mutableState.credential }
|
|
|
+ set { $mutableState.credential = newValue }
|
|
|
}
|
|
|
|
|
|
// MARK: Validators
|
|
|
@@ -193,7 +193,7 @@ public class Request {
|
|
|
// MARK: URLRequests
|
|
|
|
|
|
/// All `URLRequests` created on behalf of the `Request`, including original and adapted requests.
|
|
|
- public var requests: [URLRequest] { mutableState.requests }
|
|
|
+ public var requests: [URLRequest] { $mutableState.requests }
|
|
|
/// First `URLRequest` created on behalf of the `Request`. May not be the first one actually executed.
|
|
|
public var firstRequest: URLRequest? { requests.first }
|
|
|
/// Last `URLRequest` created on behalf of the `Request`.
|
|
|
@@ -214,7 +214,7 @@ public class Request {
|
|
|
// MARK: Tasks
|
|
|
|
|
|
/// All `URLSessionTask`s created on behalf of the `Request`.
|
|
|
- public var tasks: [URLSessionTask] { mutableState.tasks }
|
|
|
+ public var tasks: [URLSessionTask] { $mutableState.tasks }
|
|
|
/// First `URLSessionTask` created on behalf of the `Request`.
|
|
|
public var firstTask: URLSessionTask? { tasks.first }
|
|
|
/// Last `URLSessionTask` crated on behalf of the `Request`.
|
|
|
@@ -225,7 +225,7 @@ public class Request {
|
|
|
// MARK: Metrics
|
|
|
|
|
|
/// All `URLSessionTaskMetrics` gathered on behalf of the `Request`. Should correspond to the `tasks` created.
|
|
|
- public var allMetrics: [URLSessionTaskMetrics] { mutableState.metrics }
|
|
|
+ public var allMetrics: [URLSessionTaskMetrics] { $mutableState.metrics }
|
|
|
/// First `URLSessionTaskMetrics` gathered on behalf of the `Request`.
|
|
|
public var firstMetrics: URLSessionTaskMetrics? { allMetrics.first }
|
|
|
/// Last `URLSessionTaskMetrics` gathered on behalf of the `Request`.
|
|
|
@@ -236,14 +236,14 @@ public class Request {
|
|
|
// MARK: Retry Count
|
|
|
|
|
|
/// Number of times the `Request` has been retried.
|
|
|
- public var retryCount: Int { mutableState.retryCount }
|
|
|
+ public var retryCount: Int { $mutableState.retryCount }
|
|
|
|
|
|
// MARK: Error
|
|
|
|
|
|
/// `Error` returned from Alamofire internally, from the network request directly, or any validators executed.
|
|
|
public fileprivate(set) var error: AFError? {
|
|
|
- get { mutableState.error }
|
|
|
- set { mutableState.error = newValue }
|
|
|
+ get { $mutableState.error }
|
|
|
+ set { $mutableState.error = newValue }
|
|
|
}
|
|
|
|
|
|
/// Default initializer for the `Request` superclass.
|
|
|
@@ -511,9 +511,9 @@ public class Request {
|
|
|
func finish(error: AFError? = nil) {
|
|
|
dispatchPrecondition(condition: .onQueue(underlyingQueue))
|
|
|
|
|
|
- guard !mutableState.isFinishing else { return }
|
|
|
+ guard !$mutableState.isFinishing else { return }
|
|
|
|
|
|
- mutableState.isFinishing = true
|
|
|
+ $mutableState.isFinishing = true
|
|
|
|
|
|
if let error = error { self.error = error }
|
|
|
|
|
|
@@ -752,7 +752,7 @@ public class Request {
|
|
|
/// - Returns: The instance.
|
|
|
@discardableResult
|
|
|
public func authenticate(with credential: URLCredential) -> Self {
|
|
|
- mutableState.credential = credential
|
|
|
+ $mutableState.credential = credential
|
|
|
|
|
|
return self
|
|
|
}
|
|
|
@@ -768,7 +768,7 @@ public class Request {
|
|
|
/// - Returns: The instance.
|
|
|
@discardableResult
|
|
|
public func downloadProgress(queue: DispatchQueue = .main, closure: @escaping ProgressHandler) -> Self {
|
|
|
- mutableState.downloadProgressHandler = (handler: closure, queue: queue)
|
|
|
+ $mutableState.downloadProgressHandler = (handler: closure, queue: queue)
|
|
|
|
|
|
return self
|
|
|
}
|
|
|
@@ -784,7 +784,7 @@ public class Request {
|
|
|
/// - Returns: The instance.
|
|
|
@discardableResult
|
|
|
public func uploadProgress(queue: DispatchQueue = .main, closure: @escaping ProgressHandler) -> Self {
|
|
|
- mutableState.uploadProgressHandler = (handler: closure, queue: queue)
|
|
|
+ $mutableState.uploadProgressHandler = (handler: closure, queue: queue)
|
|
|
|
|
|
return self
|
|
|
}
|
|
|
@@ -1538,14 +1538,14 @@ public class DownloadRequest: Request {
|
|
|
/// - Note: For more information about `resumeData`, see [Apple's documentation](https://developer.apple.com/documentation/foundation/urlsessiondownloadtask/1411634-cancel).
|
|
|
public var resumeData: Data? {
|
|
|
#if !(os(Linux) || os(Windows))
|
|
|
- return mutableDownloadState.resumeData ?? error?.downloadResumeData
|
|
|
+ return $mutableDownloadState.resumeData ?? error?.downloadResumeData
|
|
|
#else
|
|
|
- return mutableDownloadState.resumeData
|
|
|
+ return $mutableDownloadState.resumeData
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
/// If the download is successful, the `URL` where the file was downloaded.
|
|
|
- public var fileURL: URL? { mutableDownloadState.fileURL }
|
|
|
+ public var fileURL: URL? { $mutableDownloadState.fileURL }
|
|
|
|
|
|
// MARK: Initial State
|
|
|
|
|
|
@@ -1603,7 +1603,7 @@ public class DownloadRequest: Request {
|
|
|
eventMonitor?.request(self, didFinishDownloadingUsing: task, with: result)
|
|
|
|
|
|
switch result {
|
|
|
- case let .success(url): mutableDownloadState.fileURL = url
|
|
|
+ case let .success(url): $mutableDownloadState.fileURL = url
|
|
|
case let .failure(error): self.error = error
|
|
|
}
|
|
|
}
|
|
|
@@ -1697,7 +1697,7 @@ public class DownloadRequest: Request {
|
|
|
// Resume to ensure metrics are gathered.
|
|
|
task.resume()
|
|
|
task.cancel { resumeData in
|
|
|
- self.mutableDownloadState.resumeData = resumeData
|
|
|
+ self.$mutableDownloadState.resumeData = resumeData
|
|
|
self.underlyingQueue.async { self.didCancelTask(task) }
|
|
|
completionHandler(resumeData)
|
|
|
}
|
|
|
@@ -1865,7 +1865,7 @@ public class UploadRequest: DataRequest {
|
|
|
defer { super.cleanup() }
|
|
|
|
|
|
guard
|
|
|
- let uploadable = self.uploadable,
|
|
|
+ let uploadable = uploadable,
|
|
|
case let .file(url, shouldRemove) = uploadable,
|
|
|
shouldRemove
|
|
|
else { return }
|