@@ -40,8 +40,12 @@ public protocol Server: Actor {
4040 /// The logger to use with communicating server activity.
4141 var logger : Logger { get }
4242
43+ /// The `URLSession` to use for all server calls.
44+ var urlSession : URLSession { get }
45+
4346 /// Designated initializer
4447 init (
48+ urlSession: URLSession ,
4549 environments: [ ServerEnvironment ] ,
4650 currentEnvironment: ServerEnvironment ? ,
4751 additionalHTTPHeaders: [ String : String ] ? ,
@@ -111,6 +115,10 @@ public extension Server {
111115 return Logger ( subsystem: Bundle . main. bundleIdentifier ?? " com.Coordinator " , category: String ( describing: Self . self) )
112116 }
113117
118+ var urlSession : URLSession {
119+ URLSession . shared
120+ }
121+
114122 // GETs
115123 func get< T: Codable > ( _ api: any ServerAPI , additionalHeaders: [ String : String ] ? = nil , queries: [ URLQueryItem ] ? = nil , httpBodyOverride httpBody: Data ? = nil , timeoutInterval: TimeInterval ? = nil , dateDecodingStrategy: JSONDecoder . DateDecodingStrategy = . iso8601, keyDecodingStrategy: JSONDecoder . KeyDecodingStrategy = . useDefaultKeys) async throws -> T {
116124 if self . blockAllAPIsNotSupported {
@@ -341,7 +349,7 @@ public extension Server {
341349 self . logger. info ( " \( Date ( ) ) - ( \( requestUID) ) Request to \( String ( describing: request. url? . description) ) [Start] " )
342350 }
343351
344- let ( data, response) = try await URLSession . shared . data ( for: request)
352+ let ( data, response) = try await self . urlSession . data ( for: request)
345353
346354 self . requestsBeingProcessed. remove ( requestUID)
347355
@@ -371,7 +379,7 @@ public extension Server {
371379 logger. info ( " \( Date ( ) ) - ( \( requestUID) ) Request to \( String ( describing: request. url? . description) ) [Start] " )
372380 }
373381
374- let ( _, response) = try await URLSession . shared . data ( for: request)
382+ let ( _, response) = try await self . urlSession . data ( for: request)
375383
376384 self . requestsBeingProcessed. remove ( requestUID)
377385
0 commit comments