Browse Source

Fixes after bad merges.

Jon Shier 8 năm trước cách đây
mục cha
commit
af7c2a9f87

+ 0 - 2
Source/Mutex+Protector.swift

@@ -77,7 +77,6 @@ final class Mutex: Lock {
         let result = pthread_mutex_unlock(&mutex)
         assert(result == 0, "Failed to unlock mutex")
     }
-}
 
     /// Execute a value producing closure while aquiring the mutex.
     ///
@@ -111,7 +110,6 @@ final class UnfairLock: Lock {
     fileprivate func unlock() {
         os_unfair_lock_unlock(&unfairLock)
     }
-}
 
     /// Execute a value producing closure while aquiring the lock.
     ///

+ 0 - 65
Source/ResponseSerialization.swift

@@ -65,7 +65,6 @@ public extension DownloadResponseSerializerProtocol where Self: DataResponseSeri
         }
 
         do {
-            let data = try Data(contentsOf: fileURL)
             return try serialize(request: request, response: response, data: data, error: error)
         } catch {
             throw error
@@ -125,7 +124,6 @@ public final class AnyResponseSerializer<Value>: ResponseSerializer {
             }
 
             do {
-                let data = try Data(contentsOf: fileURL)
                 return try serialize(request: request, response: response, data: data, error: error)
             } catch {
                 throw error
@@ -605,68 +603,5 @@ extension DataRequest {
     }
 }
 
-extension DownloadRequest {
-    /// Adds a handler to be called once the request has finished.
-    ///
-    /// - Parameters:
-    ///   - queue:             The queue on which the completion handler is dispatched. Defaults to `nil`, which means
-    ///                        the handler is called on `.main`.
-    ///   - options:           The property list reading options. Defaults to `[]`.
-    ///   - completionHandler: A closure to be executed once the request has finished.
-    /// - Returns:             The request.
-    @discardableResult
-    public func responsePropertyList(
-        queue: DispatchQueue? = nil,
-        options: PropertyListSerialization.ReadOptions = [],
-        completionHandler: @escaping (DownloadResponse<Any>) -> Void)
-        -> Self
-    {
-        return response(
-            queue: queue,
-            responseSerializer: PropertyListResponseSerializer(options: options),
-            completionHandler: completionHandler
-        )
-    }
-}
-
-// MARK: - PropertyList Decodable
-
-/// A `ResponseSerializer` that decodes the response data as a generic value using a `PropertyListDecoder`. By default,
-/// a request returning `nil` or no data is considered an error. However, if the response is has a status code valid for
-/// empty responses (`204`, `205`), then the `Empty.response` value is returned.
-public final class PropertyListDecodableResponseSerializer<T: Decodable>: ResponseSerializer {
-    let decoder: PropertyListDecoder
-
-
-    /// Creates an instance with the given `JSONDecoder` instance.
-    ///
-    /// - Parameter decoder: A decoder. Defaults to a `PropertyListDecoder` with default settings.
-    public init(decoder: PropertyListDecoder = PropertyListDecoder()) {
-        self.decoder = decoder
-    }
-
-    public func serialize(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: Error?) -> Result<T> {
-        guard error == nil else { return .failure(error!) }
-
-        guard let validData = data, validData.count > 0 else {
-            if let response = response, emptyDataStatusCodes.contains(response.statusCode) {
-                guard let emptyResponse = Empty.response as? T else {
-                    return .failure(AFError.responseSerializationFailed(reason: .invalidEmptyResponse(type: "\(T.self)")))
-                }
-
-                return .success(emptyResponse)
-            }
-
-            return .failure(AFError.responseSerializationFailed(reason: .inputDataNilOrZeroLength))
-        }
-
-        do {
-            return .success(try decoder.decode(T.self, from: validData))
-        } catch {
-            return .failure(error)
-        }
-    }
-}
-
 /// A set of HTTP response status code that do not contain response data.
 private let emptyDataStatusCodes: Set<Int> = [204, 205]

+ 1 - 1
Source/SessionManager.swift

@@ -62,7 +62,7 @@ open class SessionManager {
             } else {
                 encodings = ["gzip", "deflate"]
             }
-            
+
             return encodings.enumerated().map { (index, encoding) in
                 let quality = 1.0 - (Double(index) * 0.1)
                 return "\(encoding);q=\(quality)"

+ 8 - 8
Tests/SessionManagerTests.swift

@@ -254,9 +254,9 @@ class SessionManagerTestCase: BaseTestCase {
         let expectedUserAgent = "Unknown/Unknown (Unknown; build:Unknown; \(osNameVersion)) \(alamofireVersion)"
         XCTAssertEqual(userAgent, expectedUserAgent)
     }
-    
+
     // MARK: Tests - Supported Accept-Encodings
-    
+
     func testDefaultAcceptEncodingSupportsAppropriateEncodingsOnAppropriateSystems() {
         // Given
         let brotliURL = URL(string: "https://httpbin.org/brotli")!
@@ -268,32 +268,32 @@ class SessionManagerTestCase: BaseTestCase {
         var brotliResponse: DataResponse<Any>?
         var gzipResponse: DataResponse<Any>?
         var deflateResponse: DataResponse<Any>?
-        
+
         // When
         Alamofire.request(brotliURL).responseJSON { (response) in
             brotliResponse = response
             brotliExpectation.fulfill()
         }
-        
+
         Alamofire.request(gzipURL).responseJSON { (response) in
             gzipResponse = response
             gzipExpectation.fulfill()
         }
-        
+
         Alamofire.request(deflateURL).responseJSON { (response) in
             deflateResponse = response
             deflateExpectation.fulfill()
         }
-        
+
         waitForExpectations(timeout: 5, handler: nil)
-        
+
         // Then
         if #available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *) {
             XCTAssertTrue(brotliResponse?.result.isSuccess == true)
         } else {
             XCTAssertFalse(brotliResponse?.result.isSuccess == true)
         }
-        
+
         XCTAssertTrue(gzipResponse?.result.isSuccess == true)
         XCTAssertTrue(deflateResponse?.result.isSuccess == true)
     }