extensionRequest: CustomStringConvertible { /// A textual representation of this instance, including the `HTTPMethod` and `URL` if the `URLRequest` has been /// created, as well as the response status code, if a response has been received. publicvar description: String { guardlet request = performedRequests.last ?? lastRequest, let url = request.url, let method = request.httpMethod else { return"No request created yet." }
let requestDescription ="\(method)\(url.absoluteString)"
/// Type describing the source used to create the underlying `URLSessionDownloadTask`.
publicenumDownloadable {
/// Download should be started from the `URLRequest` produced by the associated `URLRequestConvertible` value.
case request(URLRequestConvertible)
/// Download should be started from the associated resume `Data` value.
case resumeData(Data)
}
UploadableConvertible
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/// A type that can produce an `UploadRequest.Uploadable` value. publicprotocolUploadableConvertible { /// Produces an `UploadRequest.Uploadable` value from the instance. /// /// - Returns: The `UploadRequest.Uploadable`. /// - Throws: Any `Error` produced during creation. funccreateUploadable() throws -> UploadRequest.Uploadable }
/// A type that can be converted to an upload, whether from an `UploadRequest.Uploadable` or `URLRequestConvertible`. publicprotocolUploadConvertible: UploadableConvertible & URLRequestConvertible {}
/// Protected `MutableState` value that provides thread-safe access to state values. fileprivatelet protectedMutableState: Protector<MutableState> =Protector(MutableState())
/// `State` of the `Request`. publicvar state: State { return protectedMutableState.directValue.state } /// Returns whether `state` is `.initialized`. publicvar isInitialized: Bool { return state == .initialized } /// Returns whether `state is `.resumed`. publicvar isResumed: Bool { return state == .resumed } /// Returns whether `state` is `.suspended`. publicvar isSuspended: Bool { return state == .suspended } /// Returns whether `state` is `.cancelled`. publicvar isCancelled: Bool { return state == .cancelled } /// Returns whether `state` is `.finished`. publicvar isFinished: Bool { return state == .finished }
/// Protected `MutableState` value that provides thread-safe access to state values. fileprivatelet protectedMutableState: Protector<MutableState> =Protector(MutableState())
structMutableState { /// State of the `Request`. var state: State= .initialized /// `ProgressHandler` and `DispatchQueue` provided for upload progress callbacks. var uploadProgressHandler: (handler: ProgressHandler, queue: DispatchQueue)? /// `ProgressHandler` and `DispatchQueue` provided for download progress callbacks. var downloadProgressHandler: (handler: ProgressHandler, queue: DispatchQueue)? /// `RedirectHandler` provided for to handle request redirection. var redirectHandler: RedirectHandler? /// `CachedResponseHandler` provided to handle response caching. var cachedResponseHandler: CachedResponseHandler? /// Closure called when the `Request` is able to create a cURL description of itself. var cURLHandler: ((String) -> Void)? /// Response serialization closures that handle response parsing. var responseSerializers: [() -> Void] = [] /// Response serialization completion closures executed once all response serializers are complete. var responseSerializerCompletions: [() -> Void] = [] /// Whether response serializer processing is finished. var responseSerializerProcessingFinished =false /// `URLCredential` used for authentication challenges. var credential: URLCredential? /// All `URLRequest`s created by Alamofire on behalf of the `Request`. var requests: [URLRequest] = [] /// All `URLSessionTask`s created by Alamofire on behalf of the `Request`. var tasks: [URLSessionTask] = [] /// All `URLSessionTaskMetrics` values gathered by Alamofire on behalf of the `Request`. Should correspond /// exactly the the `tasks` created. var metrics: [URLSessionTaskMetrics] = [] /// Number of times any retriers provided retried the `Request`. var retryCount =0 /// Final `AFError` for the `Request`, whether from various internal Alamofire calls or as a result of a `task`. var error: AFError? }
publicenumResult<Value> { case success(Value) case failure(Error)
/// Returns `true` if the result is a success, `false` otherwise. publicvar isSuccess: Bool { switchself { case .success: returntrue case .failure: returnfalse } }
/// Returns `true` if the result is a failure, `false` otherwise. publicvar isFailure: Bool { return!isSuccess }
/// Returns the associated value if the result is a success, `nil` otherwise. publicvar value: Value? { switchself { case .success(let value): return value case .failure: returnnil } }
/// Returns the associated error value if the result is a failure, `nil` otherwise. publicvar error: Error? { switchself { case .success: returnnil case .failure(let error): return error } } }
// MARK: - CustomStringConvertible
extensionResult: CustomStringConvertible { /// The textual representation used when written to an output stream, which includes whether the result was a /// success or failure. publicvar description: String { switchself { case .success: return"SUCCESS" case .failure: return"FAILURE" } } }
// MARK: - CustomDebugStringConvertible
extensionResult: CustomDebugStringConvertible { /// The debug textual representation used when written to an output stream, which includes whether the result was a /// success or failure in addition to the value or error. publicvar debugDescription: String { switchself { case .success(let value): return"SUCCESS: \(value)" case .failure(let error): return"FAILURE: \(error)" } } }
publicenumAFError: Error { /// The underlying reason the parameter encoding error occurred. /// /// - missingURL: The URL request did not have a URL to encode. /// - jsonEncodingFailed: JSON serialization failed with an underlying system error during the /// encoding process. /// - propertyListEncodingFailed: Property list serialization failed with an underlying system error during /// encoding process. publicenumParameterEncodingFailureReason { case missingURL case jsonEncodingFailed(error: Error) case propertyListEncodingFailed(error: Error) }
/// The underlying reason the multipart encoding error occurred. publicenumMultipartEncodingFailureReason { case bodyPartURLInvalid(url: URL) case bodyPartFilenameInvalid(in: URL) case bodyPartFileNotReachable(at: URL) case bodyPartFileNotReachableWithError(atURL: URL, error: Error) case bodyPartFileIsDirectory(at: URL) case bodyPartFileSizeNotAvailable(at: URL) case bodyPartFileSizeQueryFailedWithError(forURL: URL, error: Error) case bodyPartInputStreamCreationFailed(for: URL)
case outputStreamCreationFailed(for: URL) case outputStreamFileAlreadyExists(at: URL) case outputStreamURLInvalid(url: URL) case outputStreamWriteFailed(error: Error)
case inputStreamReadFailed(error: Error) } publicenumResponseValidationFailureReason { case dataFileNil case dataFileReadFailed(at: URL) case missingContentType(acceptableContentTypes: [String]) case unacceptableContentType(acceptableContentTypes: [String], responseContentType: String) case unacceptableStatusCode(code: Int) } publicenumResponseSerializationFailureReason { case inputDataNil case inputDataNilOrZeroLength case inputFileNil case inputFileReadFailed(at: URL) case stringSerializationFailed(encoding: String.Encoding) case jsonSerializationFailed(error: Error) case propertyListSerializationFailed(error: Error) }
case invalidURL(url: URLConvertible) case parameterEncodingFailed(reason: ParameterEncodingFailureReason) case multipartEncodingFailed(reason: MultipartEncodingFailureReason) case responseValidationFailed(reason: ResponseValidationFailureReason) case responseSerializationFailed(reason: ResponseSerializationFailureReason) }