123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import Foundation
- public protocol URLConvertible {
-
-
-
-
- func asURL() throws -> URL
- }
- extension String: URLConvertible {
-
-
-
-
- public func asURL() throws -> URL {
- guard let url = URL(string: self) else { throw AFError.invalidURL(url: self) }
- return url
- }
- }
- extension URL: URLConvertible {
-
- public func asURL() throws -> URL { self }
- }
- extension URLComponents: URLConvertible {
-
-
-
-
- public func asURL() throws -> URL {
- guard let url = url else { throw AFError.invalidURL(url: self) }
- return url
- }
- }
- public protocol URLRequestConvertible {
-
-
-
-
- func asURLRequest() throws -> URLRequest
- }
- extension URLRequestConvertible {
-
- public var urlRequest: URLRequest? { try? asURLRequest() }
- }
- extension URLRequest: URLRequestConvertible {
-
- public func asURLRequest() throws -> URLRequest { self }
- }
- extension URLRequest {
-
-
-
-
-
-
-
- public init(url: URLConvertible, method: HTTPMethod, headers: HTTPHeaders? = nil) throws {
- let url = try url.asURL()
- self.init(url: url)
- httpMethod = method.rawValue
- allHTTPHeaderFields = headers?.dictionary
- }
- }
|