2
0
Jon Shier 7 жил өмнө
parent
commit
97eb70f8ad

+ 4 - 4
Source/Request.swift

@@ -88,9 +88,9 @@ open class Request {
     open var response: HTTPURLResponse? {
         return finalTask?.response as? HTTPURLResponse
     }
-    
+
     // Metrics
-    
+
     private var protectedMetrics = Protector<[URLSessionTaskMetrics]>([])
     public var allMetrics: [URLSessionTaskMetrics] {
         return protectedMetrics.directValue
@@ -98,9 +98,9 @@ open class Request {
     public var firstMetrics: URLSessionTaskMetrics? { return allMetrics.first }
     public var lastMetrics: URLSessionTaskMetrics? { return allMetrics.last }
     public var metrics: URLSessionTaskMetrics? { return lastMetrics }
-    
+
     // Tasks
-    
+
     private var protectedTasks = Protector<[URLSessionTask]>([])
     public var tasks: [URLSessionTask] {
         return protectedTasks.directValue

+ 16 - 16
Source/Response.swift

@@ -40,7 +40,7 @@ public struct DataResponse<Value> {
 
     /// The final metrics of the response.
     public let metrics: URLSessionTaskMetrics?
-    
+
     /// The time taken to serialize the response.
     public let serializationDuration: TimeInterval
 
@@ -82,7 +82,7 @@ extension DataResponse: CustomStringConvertible, CustomDebugStringConvertible {
     public var description: String {
         return result.debugDescription
     }
-    
+
     /// The debug textual representation used when written to an output stream, which includes the URL request, the URL
     /// response, the server data, the response serialization result and the timeline.
     public var debugDescription: String {
@@ -91,21 +91,21 @@ extension DataResponse: CustomStringConvertible, CustomDebugStringConvertible {
             let headers = response.allHeaderFields as! HTTPHeaders
             let keys = headers.keys.sorted(by: >)
             let sortedHeaders = keys.map { "\($0): \(headers[$0]!)" }.joined(separator: "\n")
-            
+
             return """
             Status Code: \(response.statusCode)
-                Headers: \(sortedHeaders)
+                        Headers: \(sortedHeaders)
             """
         } ?? "nil"
         let metricsDescription = metrics.map { "\($0.taskInterval.duration)s" } ?? "None"
-        
+
         return """
         [Request]: \(requestDescription)
         [Response]: \(responseDescription)
         [Data]: \(data?.description ?? "None")
-        [Result]: \(result.debugDescription)
         [Network Duration]: \(metricsDescription)
         [Serialization Duration]: \(serializationDuration)s
+        [Result]: \(result.debugDescription)
         """
     }
 }
@@ -221,7 +221,7 @@ public struct DownloadResponse<Value> {
 
     /// The final metrics of the response.
     public let metrics: URLSessionTaskMetrics?
-    
+
     /// The time taken to serialize the response.
     public let serializationDuration: TimeInterval
 
@@ -230,7 +230,7 @@ public struct DownloadResponse<Value> {
 
     /// Returns the associated error value if the result if it is a failure, `nil` otherwise.
     public var error: Error? { return result.error }
-    
+
     /// Creates a `DownloadResponse` instance with the specified parameters derived from response serialization.
     ///
     /// - Parameters:
@@ -271,7 +271,7 @@ extension DownloadResponse: CustomStringConvertible, CustomDebugStringConvertibl
     public var description: String {
         return result.debugDescription
     }
-    
+
     /// The debug textual representation used when written to an output stream, which includes the URL request, the URL
     /// response, the temporary and destination URLs, the resume data, the response serialization result and the
     /// timeline.
@@ -281,24 +281,24 @@ extension DownloadResponse: CustomStringConvertible, CustomDebugStringConvertibl
             let headers = response.allHeaderFields as! HTTPHeaders
             let keys = headers.keys.sorted(by: >)
             let sortedHeaders = keys.map { "\($0): \(headers[$0]!)" }.joined(separator: "\n")
-            
+
             return """
             Status Code: \(response.statusCode)
             Headers: \(sortedHeaders)
             """
-            } ?? "nil"
+        } ?? "nil"
         let metricsDescription = metrics.map { "\($0.taskInterval.duration)s" } ?? "None"
         let resumeDataDescription = resumeData.map { "\($0)" } ?? "None"
-        
+
         return """
         [Request]: \(requestDescription)
         [Response]: \(responseDescription)
         [TemporaryURL]: \(temporaryURL?.path ?? "nil")
         [DestinationURL]: \(destinationURL?.path ?? "nil")
-        [Result]: \(result.debugDescription)
         [ResumeData]: \(resumeDataDescription)
         [Network Duration]: \(metricsDescription)
         [Serialization Duration]: \(serializationDuration)s
+        [Result]: \(result.debugDescription)
         """
     }
 }
@@ -330,7 +330,7 @@ extension DownloadResponse {
             result: result.map(transform)
         )
     }
-    
+
     /// Evaluates the given closure when the result of this `DownloadResponse` is a success, passing the unwrapped
     /// result value as a parameter.
     ///
@@ -357,7 +357,7 @@ extension DownloadResponse {
             result: result.flatMap(transform)
         )
     }
-    
+
     /// Evaluates the specified closure when the `DownloadResponse` is a failure, passing the unwrapped error as a parameter.
     ///
     /// Use the `mapError` function with a closure that does not throw. For example:
@@ -379,7 +379,7 @@ extension DownloadResponse {
             result: result.mapError(transform)
         )
     }
-    
+
     /// Evaluates the specified closure when the `DownloadResponse` is a failure, passing the unwrapped error as a parameter.
     ///
     /// Use the `flatMapError` function with a closure that may throw an error. For example:

+ 2 - 2
Source/ResponseSerialization.swift

@@ -229,7 +229,7 @@ extension DataRequest {
                                                                    data: self.data,
                                                                    error: self.error) }
             let end = CFAbsoluteTimeGetCurrent()
-            
+
             let response = DataResponse(request: self.request,
                                         response: self.response,
                                         data: self.data,
@@ -301,7 +301,7 @@ extension DownloadRequest {
                                                                            fileURL: self.fileURL,
                                                                            error: self.error) }
             let end = CFAbsoluteTimeGetCurrent()
-            
+
             let response = DownloadResponse(request: self.request,
                                             response: self.response,
                                             temporaryURL: self.temporaryURL,

+ 1 - 1
Tests/DownloadTests.swift

@@ -740,7 +740,7 @@ class DownloadResponseMapErrorTestCase: BaseTestCase {
         XCTAssertNil(response?.resumeData)
         XCTAssertNotNil(response?.error)
         XCTAssertEqual(response?.result.isFailure, true)
-        
+
         guard let error = response?.error as? TestError, case .error = error else { XCTFail(); return }
 
         XCTAssertNotNil(response?.metrics)