Skip to content

Commit

Permalink
Made it possible to change configuration of underlying URLSessionConf…
Browse files Browse the repository at this point in the history
…iguration.
  • Loading branch information
Christopher Bryan Henderson committed Oct 16, 2017
1 parent f8c5ec6 commit 9241901
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion Retrolux.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Retrolux.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -204,6 +205,7 @@
49DE43471DAAA54C00D41572 /* SelfApplyingArg.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelfApplyingArg.swift; sourceTree = "<group>"; };
49DE43491DAAA57C00D41572 /* WrappedSerializerArg.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WrappedSerializerArg.swift; sourceTree = "<group>"; };
49DE434B1DAAD82100D41572 /* Path.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Path.swift; sourceTree = "<group>"; };
D017283A1F95488000139209 /* ClientInheritanceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientInheritanceTests.swift; sourceTree = "<group>"; };
F3A3D0101D875C7A0067D03C /* Response.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Response.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -404,6 +406,7 @@
34B8EDAB1E664F2200030FAA /* something.jpg */,
4978AA8D1D35A11900E1F1A5 /* Info.plist */,
34926EE71E3020CE009E4E42 /* Sensitive.plist */,
D017283A1F95488000139209 /* ClientInheritanceTests.swift */,
);
path = RetroluxTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
9 changes: 4 additions & 5 deletions Retrolux/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions RetroluxTests/ClientInheritanceTests.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 9241901

Please sign in to comment.