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
No related branches found
No related tags found
No related merge requests found
......@@ -138,7 +138,7 @@ open class DataManager: NSObject, URLSessionDelegate
req.setValue("application/json", forHTTPHeaderField: "Accept")
}
req.timeoutInterval = self.timeout
req.timeoutInterval = request.timeout ?? self.timeout
if let authentication = request.authentication {
if let headerKey = authentication.headerKey, let headerValue = authentication.headerValue {
......
......@@ -71,7 +71,9 @@ public class Request: CustomStringConvertible
public var contentType: String?
public init(url: String, method: RequestMethod, authentication: Authentication?, parameters: [String: String] = [:], payload: Data? = nil, contentType: String?) {
public var timeout: TimeInterval?
public init(url: String, method: RequestMethod, authentication: Authentication?, parameters: [String: String] = [:], payload: Data? = nil, contentType: String?, timeout: TimeInterval?) {
self.url = url
self.method = method
self.authentication = authentication
......@@ -82,6 +84,7 @@ public class Request: CustomStringConvertible
} else {
self.contentType = nil
}
self.timeout = timeout
}
public func constructUrl() -> URL? {
......
......@@ -20,6 +20,7 @@ public class RequestBuilder
private var parameters: [String: String] = [:]
private var payload: Data?
private var contentType: String?
private var timeout: TimeInterval?
public func url(_ url: String) -> RequestBuilder {
self.url = url
......@@ -58,7 +59,12 @@ public class RequestBuilder
return self
}
public func timeout(timeout: TimeInterval) -> RequestBuilder {
self.timeout = timeout
return self
}
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