|
|
@@ -95,6 +95,18 @@ public struct GoogleXSSIPreprocessor: DataPreprocessor {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#if swift(>=5.5)
|
|
|
+extension DataPreprocessor where Self == PassthroughPreprocessor {
|
|
|
+ /// Provides a `PassthroughPreprocessor` instance.
|
|
|
+ public static var passthrough: PassthroughPreprocessor { PassthroughPreprocessor() }
|
|
|
+}
|
|
|
+
|
|
|
+extension DataPreprocessor where Self == GoogleXSSIPreprocessor {
|
|
|
+ /// Provides a `GoogleXSSIPreprocessor` instance.
|
|
|
+ public static var googleXSSI: GoogleXSSIPreprocessor { GoogleXSSIPreprocessor() }
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
extension ResponseSerializer {
|
|
|
/// Default `DataPreprocessor`. `PassthroughPreprocessor` by default.
|
|
|
public static var defaultDataPreprocessor: DataPreprocessor { PassthroughPreprocessor() }
|
|
|
@@ -199,18 +211,9 @@ extension DataRequest {
|
|
|
return self
|
|
|
}
|
|
|
|
|
|
- /// Adds a handler to be called once the request has finished.
|
|
|
- ///
|
|
|
- /// - Parameters:
|
|
|
- /// - queue: The queue on which the completion handler is dispatched. `.main` by default
|
|
|
- /// - responseSerializer: The response serializer responsible for serializing the request, response, and data.
|
|
|
- /// - completionHandler: The code to be executed once the request has finished.
|
|
|
- ///
|
|
|
- /// - Returns: The request.
|
|
|
- @discardableResult
|
|
|
- public func response<Serializer: DataResponseSerializerProtocol>(queue: DispatchQueue = .main,
|
|
|
- responseSerializer: Serializer,
|
|
|
- completionHandler: @escaping (AFDataResponse<Serializer.SerializedObject>) -> Void)
|
|
|
+ private func _response<Serializer: DataResponseSerializerProtocol>(queue: DispatchQueue = .main,
|
|
|
+ responseSerializer: Serializer,
|
|
|
+ completionHandler: @escaping (AFDataResponse<Serializer.SerializedObject>) -> Void)
|
|
|
-> Self {
|
|
|
appendResponseSerializer {
|
|
|
// Start work that should be on the serialization queue.
|
|
|
@@ -276,6 +279,38 @@ extension DataRequest {
|
|
|
|
|
|
return self
|
|
|
}
|
|
|
+
|
|
|
+ /// Adds a handler to be called once the request has finished.
|
|
|
+ ///
|
|
|
+ /// - Parameters:
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. `.main` by default
|
|
|
+ /// - responseSerializer: The response serializer responsible for serializing the request, response, and data.
|
|
|
+ /// - completionHandler: The code to be executed once the request has finished.
|
|
|
+ ///
|
|
|
+ /// - Returns: The request.
|
|
|
+ @discardableResult
|
|
|
+ public func response<Serializer: DataResponseSerializerProtocol>(queue: DispatchQueue = .main,
|
|
|
+ responseSerializer: Serializer,
|
|
|
+ completionHandler: @escaping (AFDataResponse<Serializer.SerializedObject>) -> Void)
|
|
|
+ -> Self {
|
|
|
+ _response(queue: queue, responseSerializer: responseSerializer, completionHandler: completionHandler)
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Adds a handler to be called once the request has finished.
|
|
|
+ ///
|
|
|
+ /// - Parameters:
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. `.main` by default
|
|
|
+ /// - responseSerializer: The response serializer responsible for serializing the request, response, and data.
|
|
|
+ /// - completionHandler: The code to be executed once the request has finished.
|
|
|
+ ///
|
|
|
+ /// - Returns: The request.
|
|
|
+ @discardableResult
|
|
|
+ public func response<Serializer: ResponseSerializer>(queue: DispatchQueue = .main,
|
|
|
+ responseSerializer: Serializer,
|
|
|
+ completionHandler: @escaping (AFDataResponse<Serializer.SerializedObject>) -> Void)
|
|
|
+ -> Self {
|
|
|
+ _response(queue: queue, responseSerializer: responseSerializer, completionHandler: completionHandler)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
extension DownloadRequest {
|
|
|
@@ -313,19 +348,9 @@ extension DownloadRequest {
|
|
|
return self
|
|
|
}
|
|
|
|
|
|
- /// Adds a handler to be called once the request has finished.
|
|
|
- ///
|
|
|
- /// - Parameters:
|
|
|
- /// - queue: The queue on which the completion handler is dispatched. `.main` by default.
|
|
|
- /// - responseSerializer: The response serializer responsible for serializing the request, response, and data
|
|
|
- /// contained in the destination `URL`.
|
|
|
- /// - completionHandler: The code to be executed once the request has finished.
|
|
|
- ///
|
|
|
- /// - Returns: The request.
|
|
|
- @discardableResult
|
|
|
- public func response<Serializer: DownloadResponseSerializerProtocol>(queue: DispatchQueue = .main,
|
|
|
- responseSerializer: Serializer,
|
|
|
- completionHandler: @escaping (AFDownloadResponse<Serializer.SerializedObject>) -> Void)
|
|
|
+ private func _response<Serializer: DownloadResponseSerializerProtocol>(queue: DispatchQueue = .main,
|
|
|
+ responseSerializer: Serializer,
|
|
|
+ completionHandler: @escaping (AFDownloadResponse<Serializer.SerializedObject>) -> Void)
|
|
|
-> Self {
|
|
|
appendResponseSerializer {
|
|
|
// Start work that should be on the serialization queue.
|
|
|
@@ -392,6 +417,40 @@ extension DownloadRequest {
|
|
|
|
|
|
return self
|
|
|
}
|
|
|
+
|
|
|
+ /// Adds a handler to be called once the request has finished.
|
|
|
+ ///
|
|
|
+ /// - Parameters:
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. `.main` by default.
|
|
|
+ /// - responseSerializer: The response serializer responsible for serializing the request, response, and data
|
|
|
+ /// contained in the destination `URL`.
|
|
|
+ /// - completionHandler: The code to be executed once the request has finished.
|
|
|
+ ///
|
|
|
+ /// - Returns: The request.
|
|
|
+ @discardableResult
|
|
|
+ public func response<Serializer: DownloadResponseSerializerProtocol>(queue: DispatchQueue = .main,
|
|
|
+ responseSerializer: Serializer,
|
|
|
+ completionHandler: @escaping (AFDownloadResponse<Serializer.SerializedObject>) -> Void)
|
|
|
+ -> Self {
|
|
|
+ _response(queue: queue, responseSerializer: responseSerializer, completionHandler: completionHandler)
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Adds a handler to be called once the request has finished.
|
|
|
+ ///
|
|
|
+ /// - Parameters:
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. `.main` by default.
|
|
|
+ /// - responseSerializer: The response serializer responsible for serializing the request, response, and data
|
|
|
+ /// contained in the destination `URL`.
|
|
|
+ /// - completionHandler: The code to be executed once the request has finished.
|
|
|
+ ///
|
|
|
+ /// - Returns: The request.
|
|
|
+ @discardableResult
|
|
|
+ public func response<Serializer: ResponseSerializer>(queue: DispatchQueue = .main,
|
|
|
+ responseSerializer: Serializer,
|
|
|
+ completionHandler: @escaping (AFDownloadResponse<Serializer.SerializedObject>) -> Void)
|
|
|
+ -> Self {
|
|
|
+ _response(queue: queue, responseSerializer: responseSerializer, completionHandler: completionHandler)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// MARK: - URL
|
|
|
@@ -416,6 +475,13 @@ public struct URLResponseSerializer: DownloadResponseSerializerProtocol {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#if swift(>=5.5)
|
|
|
+extension DownloadResponseSerializerProtocol where Self == URLResponseSerializer {
|
|
|
+ /// Provides a `URLResponseSerializer` instance.
|
|
|
+ public static var url: URLResponseSerializer { URLResponseSerializer() }
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
extension DownloadRequest {
|
|
|
/// Adds a handler using a `URLResponseSerializer` to be called once the request is finished.
|
|
|
///
|
|
|
@@ -441,7 +507,7 @@ public final class DataResponseSerializer: ResponseSerializer {
|
|
|
public let emptyResponseCodes: Set<Int>
|
|
|
public let emptyRequestMethods: Set<HTTPMethod>
|
|
|
|
|
|
- /// Creates an instance using the provided values.
|
|
|
+ /// Creates a `DataResponseSerializer` using the provided parameters.
|
|
|
///
|
|
|
/// - Parameters:
|
|
|
/// - dataPreprocessor: `DataPreprocessor` used to prepare the received `Data` for serialization.
|
|
|
@@ -472,6 +538,29 @@ public final class DataResponseSerializer: ResponseSerializer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#if swift(>=5.5)
|
|
|
+extension ResponseSerializer where Self == DataResponseSerializer {
|
|
|
+ /// Provides a default `DataResponseSerializer` instance.
|
|
|
+ public static var data: DataResponseSerializer { DataResponseSerializer() }
|
|
|
+
|
|
|
+ /// Creates a `DataResponseSerializer` using the provided parameters.
|
|
|
+ ///
|
|
|
+ /// - Parameters:
|
|
|
+ /// - dataPreprocessor: `DataPreprocessor` used to prepare the received `Data` for serialization.
|
|
|
+ /// - emptyResponseCodes: The HTTP response codes for which empty responses are allowed. `[204, 205]` by default.
|
|
|
+ /// - emptyRequestMethods: The HTTP request methods for which empty responses are allowed. `[.head]` by default.
|
|
|
+ ///
|
|
|
+ /// - Returns: The `DataResponseSerializer`.
|
|
|
+ public static func data(dataPreprocessor: DataPreprocessor = DataResponseSerializer.defaultDataPreprocessor,
|
|
|
+ emptyResponseCodes: Set<Int> = DataResponseSerializer.defaultEmptyResponseCodes,
|
|
|
+ emptyRequestMethods: Set<HTTPMethod> = DataResponseSerializer.defaultEmptyRequestMethods) -> DataResponseSerializer {
|
|
|
+ DataResponseSerializer(dataPreprocessor: dataPreprocessor,
|
|
|
+ emptyResponseCodes: emptyResponseCodes,
|
|
|
+ emptyRequestMethods: emptyRequestMethods)
|
|
|
+ }
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
extension DataRequest {
|
|
|
/// Adds a handler using a `DataResponseSerializer` to be called once the request has finished.
|
|
|
///
|
|
|
@@ -583,6 +672,33 @@ public final class StringResponseSerializer: ResponseSerializer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#if swift(>=5.5)
|
|
|
+extension ResponseSerializer where Self == StringResponseSerializer {
|
|
|
+ /// Provides a default `StringResponseSerializer` instance.
|
|
|
+ public static var string: StringResponseSerializer { StringResponseSerializer() }
|
|
|
+
|
|
|
+ /// Creates a `StringResponseSerializer` with the provided values.
|
|
|
+ ///
|
|
|
+ /// - Parameters:
|
|
|
+ /// - dataPreprocessor: `DataPreprocessor` used to prepare the received `Data` for serialization.
|
|
|
+ /// - encoding: A string encoding. Defaults to `nil`, in which case the encoding will be determined
|
|
|
+ /// from the server response, falling back to the default HTTP character set, `ISO-8859-1`.
|
|
|
+ /// - emptyResponseCodes: The HTTP response codes for which empty responses are allowed. `[204, 205]` by default.
|
|
|
+ /// - emptyRequestMethods: The HTTP request methods for which empty responses are allowed. `[.head]` by default.
|
|
|
+ ///
|
|
|
+ /// - Returns: The `StringResponseSerializer`.
|
|
|
+ public static func string(dataPreprocessor: DataPreprocessor = StringResponseSerializer.defaultDataPreprocessor,
|
|
|
+ encoding: String.Encoding? = nil,
|
|
|
+ emptyResponseCodes: Set<Int> = StringResponseSerializer.defaultEmptyResponseCodes,
|
|
|
+ emptyRequestMethods: Set<HTTPMethod> = StringResponseSerializer.defaultEmptyRequestMethods) -> StringResponseSerializer {
|
|
|
+ StringResponseSerializer(dataPreprocessor: dataPreprocessor,
|
|
|
+ encoding: encoding,
|
|
|
+ emptyResponseCodes: emptyResponseCodes,
|
|
|
+ emptyRequestMethods: emptyRequestMethods)
|
|
|
+ }
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
extension DataRequest {
|
|
|
/// Adds a handler using a `StringResponseSerializer` to be called once the request has finished.
|
|
|
///
|
|
|
@@ -856,6 +972,31 @@ public final class DecodableResponseSerializer<T: Decodable>: ResponseSerializer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#if swift(>=5.5)
|
|
|
+extension ResponseSerializer {
|
|
|
+ /// Creates a `DecodableResponseSerializer` using the values provided.
|
|
|
+ ///
|
|
|
+ /// - Parameters:
|
|
|
+ /// - type: `Decodable` type to decode from response data.
|
|
|
+ /// - dataPreprocessor: `DataPreprocessor` used to prepare the received `Data` for serialization.
|
|
|
+ /// - decoder: The `DataDecoder`. `JSONDecoder()` by default.
|
|
|
+ /// - emptyResponseCodes: The HTTP response codes for which empty responses are allowed. `[204, 205]` by default.
|
|
|
+ /// - emptyRequestMethods: The HTTP request methods for which empty responses are allowed. `[.head]` by default.
|
|
|
+ ///
|
|
|
+ /// - Returns: The `DecodableResponseSerializer`.
|
|
|
+ public static func decodable<T: Decodable>(of type: T.Type,
|
|
|
+ dataPreprocessor: DataPreprocessor = DecodableResponseSerializer<T>.defaultDataPreprocessor,
|
|
|
+ decoder: DataDecoder = JSONDecoder(),
|
|
|
+ emptyResponseCodes: Set<Int> = DecodableResponseSerializer<T>.defaultEmptyResponseCodes,
|
|
|
+ emptyRequestMethods: Set<HTTPMethod> = DecodableResponseSerializer<T>.defaultEmptyRequestMethods) -> DecodableResponseSerializer<T> where Self == DecodableResponseSerializer<T> {
|
|
|
+ DecodableResponseSerializer<T>(dataPreprocessor: dataPreprocessor,
|
|
|
+ decoder: decoder,
|
|
|
+ emptyResponseCodes: emptyResponseCodes,
|
|
|
+ emptyRequestMethods: emptyRequestMethods)
|
|
|
+ }
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
extension DataRequest {
|
|
|
/// Adds a handler using a `DecodableResponseSerializer` to be called once the request has finished.
|
|
|
///
|
|
|
@@ -869,8 +1010,6 @@ extension DataRequest {
|
|
|
/// from the server response, falling back to the default HTTP character set, `ISO-8859-1`.
|
|
|
/// - emptyResponseCodes: HTTP status codes for which empty responses are always valid. `[204, 205]` by default.
|
|
|
/// - emptyRequestMethods: `HTTPMethod`s for which empty responses are always valid. `[.head]` by default.
|
|
|
- /// - options: `JSONSerialization.ReadingOptions` used when parsing the response. `.allowFragments`
|
|
|
- /// by default.
|
|
|
/// - completionHandler: A closure to be executed once the request has finished.
|
|
|
///
|
|
|
/// - Returns: The request.
|
|
|
@@ -904,8 +1043,6 @@ extension DownloadRequest {
|
|
|
/// from the server response, falling back to the default HTTP character set, `ISO-8859-1`.
|
|
|
/// - emptyResponseCodes: HTTP status codes for which empty responses are always valid. `[204, 205]` by default.
|
|
|
/// - emptyRequestMethods: `HTTPMethod`s for which empty responses are always valid. `[.head]` by default.
|
|
|
- /// - options: `JSONSerialization.ReadingOptions` used when parsing the response. `.allowFragments`
|
|
|
- /// by default.
|
|
|
/// - completionHandler: A closure to be executed once the request has finished.
|
|
|
///
|
|
|
/// - Returns: The request.
|
|
|
@@ -950,8 +1087,9 @@ public struct DecodableStreamSerializer<T: Decodable>: DataStreamSerializer {
|
|
|
|
|
|
/// Creates an instance with the provided `DataDecoder` and `DataPreprocessor`.
|
|
|
/// - Parameters:
|
|
|
- /// - decoder: ` DataDecoder` used to decode incoming `Data`.
|
|
|
- /// - dataPreprocessor: `DataPreprocessor` used to process incoming `Data` before it's passed through the `decoder`.
|
|
|
+ /// - decoder: ` DataDecoder` used to decode incoming `Data`. `JSONDecoder()` by default.
|
|
|
+ /// - dataPreprocessor: `DataPreprocessor` used to process incoming `Data` before it's passed through the
|
|
|
+ /// `decoder`. `PassthroughPreprocessor()` by default.
|
|
|
public init(decoder: DataDecoder = JSONDecoder(), dataPreprocessor: DataPreprocessor = PassthroughPreprocessor()) {
|
|
|
self.decoder = decoder
|
|
|
self.dataPreprocessor = dataPreprocessor
|
|
|
@@ -979,6 +1117,33 @@ public struct StringStreamSerializer: DataStreamSerializer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#if swift(>=5.5)
|
|
|
+extension DataStreamSerializer {
|
|
|
+ /// Creates a `DecodableStreamSerializer` instance with the provided `DataDecoder` and `DataPreprocessor`.
|
|
|
+ ///
|
|
|
+ /// - Parameters:
|
|
|
+ /// - type: `Decodable` type to decode from stream data.
|
|
|
+ /// - decoder: ` DataDecoder` used to decode incoming `Data`. `JSONDecoder()` by default.
|
|
|
+ /// - dataPreprocessor: `DataPreprocessor` used to process incoming `Data` before it's passed through the
|
|
|
+ /// `decoder`. `PassthroughPreprocessor()` by default.
|
|
|
+ public static func decodable<T: Decodable>(of type: T.Type,
|
|
|
+ decoder: DataDecoder = JSONDecoder(),
|
|
|
+ dataPreprocessor: DataPreprocessor = PassthroughPreprocessor()) -> Self where Self == DecodableStreamSerializer<T> {
|
|
|
+ DecodableStreamSerializer<T>(decoder: decoder, dataPreprocessor: dataPreprocessor)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension DataStreamSerializer where Self == PassthroughStreamSerializer {
|
|
|
+ /// Provides a `PassthroughStreamSerializer` instance.
|
|
|
+ public static var passthrough: PassthroughStreamSerializer { PassthroughStreamSerializer() }
|
|
|
+}
|
|
|
+
|
|
|
+extension DataStreamSerializer where Self == StringStreamSerializer {
|
|
|
+ /// Provides a `StringStreamSerializer` instance.
|
|
|
+ public static var string: StringStreamSerializer { StringStreamSerializer() }
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
extension DataStreamRequest {
|
|
|
/// Adds a `StreamHandler` which performs no parsing on incoming `Data`.
|
|
|
///
|