|
|
@@ -104,14 +104,12 @@ extension DataRequest {
|
|
|
/// 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`.
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. Defaults to `.main`.
|
|
|
/// - completionHandler: The code to be executed once the request has finished.
|
|
|
/// - Returns: The request.
|
|
|
@discardableResult
|
|
|
- public func response(queue: DispatchQueue? = nil, completionHandler: @escaping (DataResponse<Data?>) -> Void) -> Self {
|
|
|
+ public func response(queue: DispatchQueue = .main, completionHandler: @escaping (DataResponse<Data?>) -> Void) -> Self {
|
|
|
appendResponseSerializer {
|
|
|
- let queue = queue ?? .main
|
|
|
let result = Result(value: self.data, error: self.error)
|
|
|
let response = DataResponse(request: self.request,
|
|
|
response: self.response,
|
|
|
@@ -131,14 +129,13 @@ extension DataRequest {
|
|
|
/// 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`.
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. Defaults to `.main`.
|
|
|
/// - 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? = nil,
|
|
|
+ queue: DispatchQueue = .main,
|
|
|
responseSerializer: Serializer,
|
|
|
completionHandler: @escaping (DataResponse<Serializer.SerializedObject>) -> Void)
|
|
|
-> Self
|
|
|
@@ -151,7 +148,6 @@ extension DataRequest {
|
|
|
error: self.error) }
|
|
|
let end = CFAbsoluteTimeGetCurrent()
|
|
|
|
|
|
- let queue: DispatchQueue = queue ?? .main
|
|
|
let response = DataResponse(request: self.request,
|
|
|
response: self.response,
|
|
|
data: self.data,
|
|
|
@@ -205,18 +201,16 @@ 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`.
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. Defaults to `.main`.
|
|
|
/// - completionHandler: The code to be executed once the request has finished.
|
|
|
/// - Returns: The request.
|
|
|
@discardableResult
|
|
|
public func response(
|
|
|
- queue: DispatchQueue? = nil,
|
|
|
+ queue: DispatchQueue = .main,
|
|
|
completionHandler: @escaping (DownloadResponse<URL?>) -> Void)
|
|
|
-> Self
|
|
|
{
|
|
|
appendResponseSerializer {
|
|
|
- let queue = queue ?? .main
|
|
|
let result = Result(value: self.fileURL , error: self.error)
|
|
|
let response = DownloadResponse(request: self.request,
|
|
|
response: self.response,
|
|
|
@@ -235,15 +229,14 @@ 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`.
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. Defaults to `.main`.
|
|
|
/// - 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<T: DownloadResponseSerializerProtocol>(
|
|
|
- queue: DispatchQueue? = nil,
|
|
|
+ queue: DispatchQueue = .main,
|
|
|
responseSerializer: T,
|
|
|
completionHandler: @escaping (DownloadResponse<T.SerializedObject>) -> Void)
|
|
|
-> Self
|
|
|
@@ -256,7 +249,6 @@ extension DownloadRequest {
|
|
|
error: self.error) }
|
|
|
let end = CFAbsoluteTimeGetCurrent()
|
|
|
|
|
|
- let queue: DispatchQueue = queue ?? .main
|
|
|
let response = DownloadResponse(request: self.request,
|
|
|
response: self.response,
|
|
|
fileURL: self.fileURL,
|
|
|
@@ -312,13 +304,12 @@ extension DataRequest {
|
|
|
/// 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`.
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. Defaults to `.main`.
|
|
|
/// - completionHandler: The code to be executed once the request has finished.
|
|
|
/// - Returns: The request.
|
|
|
@discardableResult
|
|
|
public func responseData(
|
|
|
- queue: DispatchQueue? = nil,
|
|
|
+ queue: DispatchQueue = .main,
|
|
|
completionHandler: @escaping (DataResponse<Data>) -> Void)
|
|
|
-> Self
|
|
|
{
|
|
|
@@ -368,13 +359,12 @@ 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`.
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. Defaults to `.main`.
|
|
|
/// - completionHandler: The code to be executed once the request has finished.
|
|
|
/// - Returns: The request.
|
|
|
@discardableResult
|
|
|
public func responseData(
|
|
|
- queue: DispatchQueue? = nil,
|
|
|
+ queue: DispatchQueue = .main,
|
|
|
completionHandler: @escaping (DownloadResponse<Data>) -> Void)
|
|
|
-> Self
|
|
|
{
|
|
|
@@ -448,14 +438,13 @@ extension DataRequest {
|
|
|
/// 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`.
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. Defaults to `.main`.
|
|
|
/// - encoding: The 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`.
|
|
|
/// - completionHandler: A closure to be executed once the request has finished.
|
|
|
/// - Returns: The request.
|
|
|
@discardableResult
|
|
|
- public func responseString(queue: DispatchQueue? = nil,
|
|
|
+ public func responseString(queue: DispatchQueue = .main,
|
|
|
encoding: String.Encoding? = nil,
|
|
|
completionHandler: @escaping (DataResponse<String>) -> Void) -> Self {
|
|
|
return response(queue: queue,
|
|
|
@@ -468,15 +457,14 @@ 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`.
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. Defaults to `.main`.
|
|
|
/// - encoding: The 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`.
|
|
|
/// - completionHandler: A closure to be executed once the request has finished.
|
|
|
/// - Returns: The request.
|
|
|
@discardableResult
|
|
|
public func responseString(
|
|
|
- queue: DispatchQueue? = nil,
|
|
|
+ queue: DispatchQueue = .main,
|
|
|
encoding: String.Encoding? = nil,
|
|
|
completionHandler: @escaping (DownloadResponse<String>) -> Void)
|
|
|
-> Self
|
|
|
@@ -540,13 +528,12 @@ extension DataRequest {
|
|
|
/// 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`.
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. Defaults to `.main`.
|
|
|
/// - options: The JSON serialization reading options. Defaults to `.allowFragments`.
|
|
|
/// - completionHandler: A closure to be executed once the request has finished.
|
|
|
/// - Returns: The request.
|
|
|
@discardableResult
|
|
|
- public func responseJSON(queue: DispatchQueue? = nil,
|
|
|
+ public func responseJSON(queue: DispatchQueue = .main,
|
|
|
options: JSONSerialization.ReadingOptions = .allowFragments,
|
|
|
completionHandler: @escaping (DataResponse<Any>) -> Void) -> Self {
|
|
|
return response(queue: queue,
|
|
|
@@ -559,14 +546,13 @@ 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`.
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. Defaults to `.main`.
|
|
|
/// - options: The JSON serialization reading options. Defaults to `.allowFragments`.
|
|
|
/// - completionHandler: A closure to be executed once the request has finished.
|
|
|
/// - Returns: The request.
|
|
|
@discardableResult
|
|
|
public func responseJSON(
|
|
|
- queue: DispatchQueue? = nil,
|
|
|
+ queue: DispatchQueue = .main,
|
|
|
options: JSONSerialization.ReadingOptions = .allowFragments,
|
|
|
completionHandler: @escaping (DownloadResponse<Any>) -> Void)
|
|
|
-> Self
|
|
|
@@ -667,14 +653,13 @@ extension DataRequest {
|
|
|
/// 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`.
|
|
|
+ /// - queue: The queue on which the completion handler is dispatched. Defaults to `.main`.
|
|
|
/// - decoder: The `DataDecoder` to use to decode the response. Defaults to a `JSONDecoder` with default
|
|
|
/// settings.
|
|
|
/// - completionHandler: A closure to be executed once the request has finished.
|
|
|
/// - Returns: The request.
|
|
|
@discardableResult
|
|
|
- public func responseDecodable<T: Decodable>(queue: DispatchQueue? = nil,
|
|
|
+ public func responseDecodable<T: Decodable>(queue: DispatchQueue = .main,
|
|
|
decoder: DataDecoder = JSONDecoder(),
|
|
|
completionHandler: @escaping (DataResponse<T>) -> Void) -> Self {
|
|
|
return response(queue: queue,
|