Skip to content

Commit 86e958f

Browse files
stfnhdrStefan Haider
andauthored
Add URLSessionConfiguration to Fetch.Config (#22)
* add URLSessionConfiguration to Fetch Config * added documentation Co-authored-by: Stefan Haider <[email protected]>
1 parent ce5ea3e commit 86e958f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Fetch/Code/Network/APIClient.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public struct Config {
1515
public var baseURL: URL
1616
public var defaultHeaders: HTTPHeaders
1717
public var timeout: TimeInterval
18+
public var urlSession: URLSessionConfiguration
1819
public var eventMonitors: [EventMonitor]
1920
public var interceptor: RequestInterceptor?
2021
public var decoder: ResourceDecoderProtocol
@@ -30,6 +31,7 @@ public struct Config {
3031
/// - baseURL: The base `URL` used for all request, if not specified by the `Resource`
3132
/// - defaultHeaders: The `HTTPHeaders` used for all request, if not specified by the `Resource`
3233
/// - timeout: The request timeout interval controls how long (in seconds) a task should wait for additional data to arrive before giving up
34+
/// - urlSession: The `URLSessionConfiguration` passed to the Alamofire `Session`
3335
/// - eventMonitors: The `EventMonitor` array passed to the Alamofire `Session`
3436
/// - adapter: The `RequestAdapter` passed to the Alamofire `Session`
3537
/// - retrier: The `RequestRetrier` passed to the Alamofire `Session`
@@ -42,6 +44,7 @@ public struct Config {
4244
public init(baseURL: URL,
4345
defaultHeaders: HTTPHeaders = HTTPHeaders.default,
4446
timeout: TimeInterval = 60 * 2,
47+
urlSession: URLSessionConfiguration = URLSessionConfiguration.default,
4548
eventMonitors: [EventMonitor] = [APILogger(verbose: true)],
4649
interceptor: RequestInterceptor? = nil,
4750
jsonDecoder: ResourceDecoderProtocol = JSONDecoder(),
@@ -53,6 +56,7 @@ public struct Config {
5356
self.baseURL = baseURL
5457
self.defaultHeaders = defaultHeaders
5558
self.timeout = timeout
59+
self.urlSession = urlSession
5660
self.eventMonitors = eventMonitors
5761
self.interceptor = interceptor
5862
self.decoder = jsonDecoder
@@ -116,7 +120,7 @@ public class APIClient {
116120
public func setup(with config: Config) {
117121
self._config = config
118122

119-
let configuration = URLSessionConfiguration.default
123+
let configuration = config.urlSession
120124
configuration.protocolClasses = config.protocolClasses + [StubbedURL.self]
121125
configuration.timeoutIntervalForRequest = config.timeout
122126

0 commit comments

Comments
 (0)