DownloadRequest

open class DownloadRequest: Request

Specific type of Request that manages an underlying URLSessionDownloadTask.

  • A closure executed once a download request has successfully completed in order to determine where to move the temporary file written to during the download process. The closure takes two arguments: the temporary file URL and the URL response, and returns a two arguments: the file URL where the temporary file should be moved and the options defining how the file should be moved.

    Declaration

    Swift

    public typealias DownloadFileDestination = (
  • A collection of options to be executed prior to moving a downloaded file from the temporary URL to the destination URL.

    See more

    Declaration

    Swift

    public struct DownloadOptions: OptionSet
  • The resume data of the underlying download task if available after a failure.

    Declaration

    Swift

    open var resumeData: Data?
  • The progress of downloading the response data from the server for the request.

    Declaration

    Swift

    open var progress: Progress
  • Sets a closure to be called periodically during the lifecycle of the Request as data is read from the server.

    Declaration

    Swift

    open func downloadProgress(queue: DispatchQueue = DispatchQueue.main, closure: @escaping ProgressHandler) -> Self
  • Creates a download file destination closure which uses the default file manager to move the temporary file to a file URL in the first available directory with the specified search path directory and search path domain mask.

    Declaration

    Swift

    open class func suggestedDownloadDestination(
            for directory: FileManager.SearchPathDirectory = .documentDirectory,
            in domain: FileManager.SearchPathDomainMask = .userDomainMask)
            -> DownloadFileDestination
  • Validates the request, using the specified closure.

    If validation fails, subsequent calls to response handlers will have an associated error.

    Declaration

    Swift

    public func validate(_ validation: @escaping Validation) -> Self
  • Validates that the response has a status code in the specified sequence.

    If validation fails, subsequent calls to response handlers will have an associated error.

    Declaration

    Swift

    public func validate<S: Sequence>(statusCode acceptableStatusCodes: S) -> Self where S.Iterator.Element == Int
  • Validates that the response has a content type in the specified sequence.

    If validation fails, subsequent calls to response handlers will have an associated error.

    Declaration

    Swift

    public func validate<S: Sequence>(contentType acceptableContentTypes: S) -> Self where S.Iterator.Element == String
  • Validates that the response has a status code in the default acceptable range of 200…299, and that the content type matches any specified in the Accept HTTP header field.

    If validation fails, subsequent calls to response handlers will have an associated error.

    Declaration

    Swift

    public func validate() -> Self