Skip to content
Snippets Groups Projects
Commit f2b4e2f2 authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Provide optional timeout per request

parent f78a20a5
Branches feature/async
No related tags found
No related merge requests found
...@@ -138,7 +138,7 @@ open class DataManager: NSObject, URLSessionDelegate ...@@ -138,7 +138,7 @@ open class DataManager: NSObject, URLSessionDelegate
req.setValue("application/json", forHTTPHeaderField: "Accept") req.setValue("application/json", forHTTPHeaderField: "Accept")
} }
req.timeoutInterval = self.timeout req.timeoutInterval = request.timeout ?? self.timeout
if let authentication = request.authentication { if let authentication = request.authentication {
if let headerKey = authentication.headerKey, let headerValue = authentication.headerValue { if let headerKey = authentication.headerKey, let headerValue = authentication.headerValue {
......
...@@ -70,8 +70,10 @@ public class Request: CustomStringConvertible ...@@ -70,8 +70,10 @@ public class Request: CustomStringConvertible
public var payload: Data? public var payload: Data?
public var contentType: String? public var contentType: String?
public var timeout: TimeInterval?
public init(url: String, method: RequestMethod, authentication: Authentication?, parameters: [String: String] = [:], payload: Data? = nil, contentType: String?) { public init(url: String, method: RequestMethod, authentication: Authentication?, parameters: [String: String] = [:], payload: Data? = nil, contentType: String?, timeout: TimeInterval?) {
self.url = url self.url = url
self.method = method self.method = method
self.authentication = authentication self.authentication = authentication
...@@ -82,6 +84,7 @@ public class Request: CustomStringConvertible ...@@ -82,6 +84,7 @@ public class Request: CustomStringConvertible
} else { } else {
self.contentType = nil self.contentType = nil
} }
self.timeout = timeout
} }
public func constructUrl() -> URL? { public func constructUrl() -> URL? {
......
...@@ -20,6 +20,7 @@ public class RequestBuilder ...@@ -20,6 +20,7 @@ public class RequestBuilder
private var parameters: [String: String] = [:] private var parameters: [String: String] = [:]
private var payload: Data? private var payload: Data?
private var contentType: String? private var contentType: String?
private var timeout: TimeInterval?
public func url(_ url: String) -> RequestBuilder { public func url(_ url: String) -> RequestBuilder {
self.url = url self.url = url
...@@ -58,7 +59,12 @@ public class RequestBuilder ...@@ -58,7 +59,12 @@ public class RequestBuilder
return self return self
} }
public func timeout(timeout: TimeInterval) -> RequestBuilder {
self.timeout = timeout
return self
}
public func build() -> Request { public func build() -> Request {
Request(url: url, method: method, authentication: authentication, parameters: parameters, payload: payload, contentType: contentType) Request(url: url, method: method, authentication: authentication, parameters: parameters, payload: payload, contentType: contentType, timeout: timeout)
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment