Browse Source

Added internal fileURL property for choosing temp or destination URL.

Christian Noon 9 years ago
parent
commit
8870ded65a

+ 1 - 1
Source/ResponseSerialization.swift

@@ -209,7 +209,7 @@ extension DownloadRequest {
             let result = responseSerializer.serializeResponse(
                 self.request,
                 self.response,
-                self.downloadDelegate.destinationURL,
+                self.downloadDelegate.fileURL,
                 self.downloadDelegate.error
             )
 

+ 2 - 0
Source/TaskDelegate.swift

@@ -317,6 +317,8 @@ class DownloadTaskDelegate: TaskDelegate, URLSessionDownloadDelegate {
     var temporaryURL: URL?
     var destinationURL: URL?
 
+    var fileURL: URL? { return destination != nil ? destinationURL : temporaryURL }
+
     // MARK: Lifecycle
 
     override init(task: URLSessionTask) {

+ 2 - 2
Source/Validation.swift

@@ -275,8 +275,8 @@ extension DownloadRequest {
     /// - returns: The request.
     @discardableResult
     public func validate<S: Sequence>(contentType acceptableContentTypes: S) -> Self where S.Iterator.Element == String {
-        return validate { _, response, temporaryURL, destinationURL in
-            let fileURL = self.downloadDelegate.destination != nil ? destinationURL : temporaryURL
+        return validate { _, response, _, _ in
+            let fileURL = self.downloadDelegate.fileURL
 
             guard let validFileURL = fileURL else {
                 return .failure(AFError.responseValidationFailed(reason: .dataFileNil))

+ 2 - 2
Tests/ValidationTests.swift

@@ -792,8 +792,8 @@ extension DataRequest {
 
 extension DownloadRequest {
     func validateDataExists() -> Self {
-        return validate { request, response, temporaryURL, destinationURL in
-            let fileURL = self.downloadDelegate.destination != nil ? destinationURL : temporaryURL
+        return validate { request, response, _, _ in
+            let fileURL = self.downloadDelegate.fileURL
 
             guard let validFileURL = fileURL else { return .failure(ValidationError.missingFile) }