Skip to content

Commit a0bf139

Browse files
committed
Make interceptor registration thread safe.
1 parent a8dc7a1 commit a0bf139

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎Sources/SwiftRestRequests/RestApiCaller.swift‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ open class RestApiCaller : NSObject {
7373
/// Cookie storage used by the session (if provided).
7474
let httpCookieStorage: HTTPCookieStorage?
7575

76+
private let interceptorLock = NSLock()
77+
7678
/// Registered request/response interceptors (empty by default).
7779
var interceptors: [URLRequestInterceptor] = []
7880

@@ -342,6 +344,10 @@ open class RestApiCaller : NSObject {
342344
/// - Parameter interceptor: Interceptor appended to the invocation chain.
343345
public func registerRequestInterceptor(_ interceptor: URLRequestInterceptor) {
344346
logger.info("Registering request interceptor: \(interceptor)")
347+
348+
interceptorLock.lock()
349+
defer { interceptorLock.unlock() }
350+
345351
interceptors.append(interceptor)
346352
}
347353

0 commit comments

Comments
 (0)