Builder
open class Builder
请求构建器,可继承
继承HTTPRequest并重载Builder示例:
class AppRequest: HTTPRequest {
class Builder: HTTPRequest.Builder {
override func build() -> AppRequest {
return AppRequest(builder: self)
}
}
}
使用AppRequest.Builder示例:
let request = AppRequest.Builder()/*...*/.build()
-
只读属性
Declaration
Swift
public private(set) var baseUrl: String? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestUrl: String? { get }
-
Undocumented
Declaration
Swift
public private(set) var cdnUrl: String? { get }
-
Undocumented
Declaration
Swift
public private(set) var useCDN: Bool? { get }
-
Undocumented
Declaration
Swift
public private(set) var allowsCellularAccess: Bool? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestTimeoutInterval: TimeInterval? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestCachePolicy: URLRequest.CachePolicy? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestMethod: RequestMethod? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestArgument: Any? { get }
-
Undocumented
Declaration
Swift
public private(set) var constructingBodyBlock: (@Sendable (RequestMultipartFormData) -> Void)? { get }
-
Undocumented
Declaration
Swift
public private(set) var resumableDownloadPath: String? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestSerializerType: RequestSerializerType? { get }
-
Undocumented
Declaration
Swift
public private(set) var responseSerializerType: ResponseSerializerType? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestAuthorizationHeaders: [String]? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestHeaders: [String : String]? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestPriority: RequestPriority? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestUserInfo: [AnyHashable : Any]? { get }
-
Undocumented
Declaration
Swift
public private(set) var customUrlRequest: URLRequest? { get }
-
Undocumented
Declaration
Swift
public private(set) var isSynchronously: Bool? { get }
-
Undocumented
Declaration
Swift
public private(set) var tag: Int? { get }
-
Undocumented
Declaration
Swift
public private(set) var statusCodeValidator: (@Sendable (_ request: HTTPRequest) -> Bool)? { get }
-
Undocumented
Declaration
Swift
public private(set) var jsonValidator: Any? { get }
-
Undocumented
Declaration
Swift
public private(set) var urlRequestFilter: (@Sendable (_ request: HTTPRequest, _ urlRequest: inout URLRequest) -> Void)? { get }
-
Undocumented
Declaration
Swift
public private(set) var responseFilter: (@Sendable (_ request: HTTPRequest) throws -> Void)? { get }
-
Undocumented
Declaration
Swift
public private(set) var responseMockValidator: (@Sendable (HTTPRequest) -> Bool)? { get }
-
Undocumented
Declaration
Swift
public private(set) var responseMockProcessor: (@Sendable (HTTPRequest) -> Bool)? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestRetryCount: Int? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestRetryInterval: TimeInterval? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestRetryTimeout: TimeInterval? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestRetryValidator: (@Sendable (_ request: HTTPRequest, _ response: HTTPURLResponse, _ responseObject: Any?, _ error: Error?) -> Bool)? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestRetryProcessor: (@Sendable (_ request: HTTPRequest, _ response: HTTPURLResponse, _ responseObject: Any?, _ error: Error?, _ completionHandler: @escaping @Sendable (Bool) -> Void) -> Void)? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestCompletePreprocessor: (@Sendable (HTTPRequest) -> Void)? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestCompleteFilter: Completion? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestFailedPreprocessor: (@Sendable (HTTPRequest) -> Void)? { get }
-
Undocumented
Declaration
Swift
public private(set) var requestFailedFilter: Completion? { get }
-
Undocumented
Declaration
Swift
public private(set) var cacheTimeInSeconds: Int? { get }
-
Undocumented
Declaration
Swift
public private(set) var cacheVersion: Int? { get }
-
Undocumented
Declaration
Swift
public private(set) var cacheSensitiveData: Any? { get }
-
Undocumented
Declaration
Swift
public private(set) var cacheArgumentFilter: (@Sendable (_ request: HTTPRequest, _ argument: Any?) -> Any?)? { get }
-
Undocumented
Declaration
Swift
public private(set) var writeCacheAsynchronously: Bool? { get }
-
构造方法
Declaration
Swift
public init()
-
请求基准URL,默认空,示例:https://www.wuyong.site
Declaration
Swift
@discardableResult public func baseUrl(_ baseUrl: String) -> Self
-
请求URL地址,默认空,示例:/v1/user
Declaration
Swift
@discardableResult public func requestUrl(_ requestUrl: String) -> Self
-
请求可选CDN地址,默认空
Declaration
Swift
@discardableResult public func cdnUrl(_ cdnUrl: String) -> Self
-
是否使用CDN
Declaration
Swift
@discardableResult public func useCDN(_ useCDN: Bool) -> Self
-
是否允许蜂窝网络访问,默认true
Declaration
Swift
@discardableResult public func allowsCellularAccess(_ allows: Bool) -> Self
-
请求超时,默认60秒
Declaration
Swift
@discardableResult public func requestTimeoutInterval(_ interval: TimeInterval) -> Self
-
自定义请求缓存策略,默认nil不处理
Declaration
Swift
@discardableResult public func requestCachePolicy(_ cachePolicy: URLRequest.CachePolicy?) -> Self
-
请求方式,默认GET
Declaration
Swift
@discardableResult public func requestMethod(_ requestMethod: RequestMethod) -> Self
-
批量添加请求参数,建议[String: Any]?,默认nil
Declaration
Swift
@discardableResult public func requestArgument(_ argument: Any?) -> Self
-
添加单个参数
Declaration
Swift
@discardableResult public func requestArgument(_ name: String, value: Any?) -> Self
-
自定义POST请求HTTP body数据
Declaration
Swift
@discardableResult public func constructingBodyBlock(_ block: (@Sendable (RequestMultipartFormData) -> Void)?) -> Self
-
断点续传下载路径
Declaration
Swift
@discardableResult public func resumableDownloadPath(_ path: String?) -> Self
-
请求序列化方式,默认HTTP
Declaration
Swift
@discardableResult public func requestSerializerType(_ serializerType: RequestSerializerType) -> Self
-
响应序列化方式,默认JSON
Declaration
Swift
@discardableResult public func responseSerializerType(_ serializerType: ResponseSerializerType) -> Self
-
HTTP请求授权Header数组,示例:[“Username”, “Password”]
Declaration
Swift
@discardableResult public func requestAuthorizationHeaders(_ array: [String]?) -> Self
-
设置HTTP请求授权用户名和密码
Declaration
Swift
@discardableResult public func requestAuthorization(username: String?, password: String?) -> Self
-
批量添加请求Header
Declaration
Swift
@discardableResult public func requestHeaders(_ headers: [String : String]?) -> Self
-
添加单个请求Header
Declaration
Swift
@discardableResult public func requestHeader(_ name: String, value: String?) -> Self
-
请求优先级,默认default
Declaration
Swift
@discardableResult public func requestPriority(_ priority: RequestPriority) -> Self
-
自定义用户信息
Declaration
Swift
@discardableResult public func requestUserInfo(_ userInfo: [AnyHashable : Any]?) -> Self
-
JSON验证器,默认支持AnyValidator
Declaration
Swift
@discardableResult public func jsonValidator(_ validator: Any?) -> Self
-
构建自定义URLRequest
Declaration
Swift
@discardableResult public func customUrlRequest(_ urlRequest: URLRequest?) -> Self
-
设置是否是同步串行请求
Declaration
Swift
@discardableResult public func synchronously(_ synchronously: Bool) -> Self
-
自定义标签,默认0
Declaration
Swift
@discardableResult public func tag(_ tag: Int) -> Self
-
状态码验证器
Declaration
Swift
@discardableResult public func statusCodeValidator(_ validator: (@Sendable (_ request: HTTPRequest) -> Bool)?) -> Self
-
请求发送前URLRequest过滤方法,默认不处理
Declaration
Swift
@discardableResult public func urlRequestFilter(_ filter: (@Sendable (_ request: HTTPRequest, _ urlRequest: inout URLRequest) -> Void)?) -> Self
-
请求回调前Response过滤方法,默认成功不抛异常
Declaration
Swift
@discardableResult public func responseFilter(_ filter: (@Sendable (_ request: HTTPRequest) throws -> Void)?) -> Self
-
调试请求Mock验证器,默认判断404
Declaration
Swift
@discardableResult public func responseMockValidator(_ validator: (@Sendable (_ request: HTTPRequest) -> Bool)?) -> Self
-
调试请求Mock处理器,请求失败时且回调前在后台线程调用
Declaration
Swift
@discardableResult public func responseMockProcessor(_ block: (@Sendable (_ request: HTTPRequest) -> Bool)?) -> Self
-
请求完成预处理器,后台线程调用
Declaration
Swift
@discardableResult public func requestCompletePreprocessor(_ block: (@Sendable (HTTPRequest) -> Void)?) -> Self
-
请求完成过滤器,主线程调用
Declaration
Swift
@discardableResult public func requestCompleteFilter(_ block: Completion?) -> Self
-
请求失败预处理器,后台线程调用
Declaration
Swift
@discardableResult public func requestFailedPreprocessor(_ block: (@Sendable (HTTPRequest) -> Void)?) -> Self
-
请求失败过滤器,主线程调用
Declaration
Swift
@discardableResult public func requestFailedFilter(_ block: Completion?) -> Self
-
请求重试次数,默认0
Declaration
Swift
@discardableResult public func requestRetryCount(_ count: Int) -> Self
-
请求重试间隔,默认0
Declaration
Swift
@discardableResult public func requestRetryInterval(_ interval: TimeInterval) -> Self
-
请求重试超时时间,默认0
Declaration
Swift
@discardableResult public func requestRetryTimeout(_ timeout: TimeInterval) -> Self
-
请求重试验证方法,默认检查状态码和错误
Declaration
Swift
@discardableResult public func requestRetryValidator(_ validator: (@Sendable (_ request: HTTPRequest, _ response: HTTPURLResponse, _ responseObject: Any?, _ error: Error?) -> Bool)?) -> Self
-
请求重试处理方法,回调处理状态,默认调用completionHandler(true)
Declaration
Swift
@discardableResult public func requestRetryProcessor(_ processor: (@Sendable (_ request: HTTPRequest, _ response: HTTPURLResponse, _ responseObject: Any?, _ error: Error?, _ completionHandler: @escaping @Sendable (Bool) -> Void) -> Void)?) -> Self
-
缓存有效期,默认-1不缓存
Declaration
Swift
@discardableResult public func cacheTimeInSeconds(_ seconds: Int) -> Self
-
缓存版本号,默认0
Declaration
Swift
@discardableResult public func cacheVersion(_ version: Int) -> Self
-
缓存附加数据,变化时会更新缓存
Declaration
Swift
@discardableResult public func cacheSensitiveData(_ sensitiveData: Any?) -> Self
-
缓存文件名过滤器,参数为请求参数,默认返回argument
Declaration
Swift
@discardableResult public func cacheArgumentFilter(_ filter: (@Sendable (_ request: HTTPRequest, _ argument: Any?) -> Any?)?) -> Self
-
是否异步写入缓存,默认true
Declaration
Swift
@discardableResult public func writeCacheAsynchronously(_ async: Bool) -> Self
-
构建请求,子类可重写
Declaration
Swift
open func build() -> HTTPRequest