From 9241901b6c088654d1723144578073b3876f01b9 Mon Sep 17 00:00:00 2001 From: Christopher Bryan Henderson Date: Mon, 16 Oct 2017 14:28:53 -0600 Subject: [PATCH] Made it possible to change configuration of underlying URLSessionConfiguration. --- CHANGELOG | 3 ++ Retrolux.podspec | 2 +- Retrolux.xcodeproj/project.pbxproj | 4 +++ Retrolux/HTTPClient.swift | 9 +++-- RetroluxTests/ClientInheritanceTests.swift | 39 ++++++++++++++++++++++ 5 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 RetroluxTests/ClientInheritanceTests.swift diff --git a/CHANGELOG b/CHANGELOG index 9e90039..31fe6cd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +v0.10.4 +- Made it possible to change configuration of underlying URLSessionConfiguration + v0.10.3 - Wrap all serializer errors in a common enum diff --git a/Retrolux.podspec b/Retrolux.podspec index 981c7a7..ff30792 100644 --- a/Retrolux.podspec +++ b/Retrolux.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'Retrolux' - s.version = '0.10.3' + s.version = '0.10.4' s.summary = 'An all in one networking solution, like Retrofit.' # This description is used to generate tags and improve search results. diff --git a/Retrolux.xcodeproj/project.pbxproj b/Retrolux.xcodeproj/project.pbxproj index 0f93312..7e3e616 100644 --- a/Retrolux.xcodeproj/project.pbxproj +++ b/Retrolux.xcodeproj/project.pbxproj @@ -86,6 +86,7 @@ 34F6F0601E8F0856002BA263 /* ReflectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34F6F0591E8F0856002BA263 /* ReflectorTests.swift */; }; 34F6F0611E8F0856002BA263 /* ValueTransformerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34F6F05A1E8F0856002BA263 /* ValueTransformerTests.swift */; }; 34F6F0621E8F0856002BA263 /* PropertyTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34F6F05B1E8F0856002BA263 /* PropertyTypeTests.swift */; }; + D017283B1F95488000139209 /* ClientInheritanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D017283A1F95488000139209 /* ClientInheritanceTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -204,6 +205,7 @@ 49DE43471DAAA54C00D41572 /* SelfApplyingArg.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelfApplyingArg.swift; sourceTree = ""; }; 49DE43491DAAA57C00D41572 /* WrappedSerializerArg.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WrappedSerializerArg.swift; sourceTree = ""; }; 49DE434B1DAAD82100D41572 /* Path.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Path.swift; sourceTree = ""; }; + D017283A1F95488000139209 /* ClientInheritanceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientInheritanceTests.swift; sourceTree = ""; }; F3A3D0101D875C7A0067D03C /* Response.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Response.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -404,6 +406,7 @@ 34B8EDAB1E664F2200030FAA /* something.jpg */, 4978AA8D1D35A11900E1F1A5 /* Info.plist */, 34926EE71E3020CE009E4E42 /* Sensitive.plist */, + D017283A1F95488000139209 /* ClientInheritanceTests.swift */, ); path = RetroluxTests; sourceTree = ""; @@ -614,6 +617,7 @@ 34F6F05E1E8F0856002BA263 /* PerformanceTests.swift in Sources */, 34B8EDAF1E664FF300030FAA /* Utils.swift in Sources */, 34B8ED741E664B2300030FAA /* ReflectionJSONSerializerTests.swift in Sources */, + D017283B1F95488000139209 /* ClientInheritanceTests.swift in Sources */, 34B8ED781E664B2D00030FAA /* DigestAuthTests.swift in Sources */, 34B8ED791E664B3300030FAA /* QueryTests.swift in Sources */, 34CA587A1E943EC5001F5E54 /* CustomSerializerTests.swift in Sources */, diff --git a/Retrolux/HTTPClient.swift b/Retrolux/HTTPClient.swift index 9b57817..7eb2554 100644 --- a/Retrolux/HTTPClient.swift +++ b/Retrolux/HTTPClient.swift @@ -9,16 +9,15 @@ import Foundation // TODO: Add support for ignoring SSL errors. -public class HTTPClient: NSObject, Client, URLSessionDelegate, URLSessionTaskDelegate { - public private(set) var session: URLSession! +open class HTTPClient: NSObject, Client, URLSessionDelegate, URLSessionTaskDelegate { + open var session: URLSession! public override init() { super.init() - let configuration = URLSessionConfiguration.default - session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil) + session = URLSession(configuration: .default, delegate: self, delegateQueue: nil) } - public func makeAsynchronousRequest( + open func makeAsynchronousRequest( request: inout URLRequest, callback: @escaping (_ response: ClientResponse) -> Void ) -> Task diff --git a/RetroluxTests/ClientInheritanceTests.swift b/RetroluxTests/ClientInheritanceTests.swift new file mode 100644 index 0000000..8affb93 --- /dev/null +++ b/RetroluxTests/ClientInheritanceTests.swift @@ -0,0 +1,39 @@ +// +// ClientInheritanceTests.swift +// RetroluxTests +// +// Created by Christopher Bryan Henderson on 10/16/17. +// Copyright © 2017 Bryan. All rights reserved. +// + +import Foundation +import XCTest +import Retrolux + +class ClientInheritanceTests: XCTestCase { + func testInheritance() { + class TestHTTPClient: HTTPClient { + override init() { + super.init() + let configuration = URLSessionConfiguration.default + configuration.timeoutIntervalForRequest = 5349786 + session = URLSession.init(configuration: configuration) + } + } + + let builder1 = Builder.dry() + builder1.client = TestHTTPClient() + let request1 = builder1.makeRequest(method: .post, endpoint: "endpoint", args: (), response: Void.self) + _ = request1().perform() + + let builder2 = Builder.dry() + builder2.client = HTTPClient() + let request2 = builder2.makeRequest(method: .post, endpoint: "endpoint", args: (), response: Void.self) + _ = request2().perform() + + let client1 = builder1.client as! HTTPClient + XCTAssert(client1.session.configuration.timeoutIntervalForRequest == 5349786) + let client2 = builder2.client as! HTTPClient + XCTAssert(client2.session.configuration.timeoutIntervalForRequest != 5349786) + } +}