From 63a7469e2a671723b99573cdfd171c95d73d0d3e Mon Sep 17 00:00:00 2001 From: Henrik Panhans Date: Sat, 20 Mar 2021 13:04:51 +0100 Subject: [PATCH] adding new makeURL method in preparation for future release --- HPNetwork.podspec | 2 +- LICENSE.md | 4 ++-- Sources/HPNetwork/Requests/NetworkRequest.swift | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/HPNetwork.podspec b/HPNetwork.podspec index 9154672..f544c40 100644 --- a/HPNetwork.podspec +++ b/HPNetwork.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "HPNetwork" - s.version = "1.2.0" + s.version = "1.2.1" s.summary = "A lightweight but customisable networking stack written in Swift" s.homepage = "https://panhans.dev/opensource/hpnetwork" diff --git a/LICENSE.md b/LICENSE.md index bd04920..6ce5063 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,9 +1,9 @@ MIT License -Copyright (c) 2019 Henrik Panhans +Copyright (c) 2021 Henrik Panhans Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Sources/HPNetwork/Requests/NetworkRequest.swift b/Sources/HPNetwork/Requests/NetworkRequest.swift index 4cc9761..1ad63ee 100644 --- a/Sources/HPNetwork/Requests/NetworkRequest.swift +++ b/Sources/HPNetwork/Requests/NetworkRequest.swift @@ -10,11 +10,15 @@ public protocol NetworkRequest { typealias Completion = (RequestResult) -> Void var finishingQueue: DispatchQueue { get } + @available(*, deprecated, message: "Please use makeURL instead, this property will be removed in a future release") var url: URL? { get } var httpBody: Data? { get } var urlSession: URLSession { get } + func makeURL() throws -> URL + var headerFields: [NetworkRequestHeaderField]? { get } + /// The request method that will be used var requestMethod: NetworkRequestMethod { get } var authentication: NetworkRequestAuthentication? { get } @@ -26,9 +30,7 @@ public protocol NetworkRequest { extension NetworkRequest { func makeURLRequest() throws -> URLRequest { - guard let url = url else { - throw NSError.failedToCreateRequest.withFailureReason("The URL instance to create the request is nil") - } + let url = try makeURL() var request = URLRequest(url: url) request.httpMethod = requestMethod.rawValue @@ -61,6 +63,13 @@ public extension NetworkRequest { var authentication: NetworkRequestAuthentication? { nil } + func makeURL() throws -> URL { + guard let url = url else { + throw NSError.failedToCreateRequest.withFailureReason("The URL instance to create the request is nil") + } + return url + } + func convertError(_ error: Error, data: Data?, response: URLResponse?) -> Error { error }