From b9198704da4579f3892ec95d5fbcfcc221f3a3c1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 09:10:27 +0000 Subject: [PATCH] Close #45: Injectable URLSession --- Sources/Rainmaker/Requests/Requesting.swift | 2 +- Sources/Rainmaker/Server.swift | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Sources/Rainmaker/Requests/Requesting.swift b/Sources/Rainmaker/Requests/Requesting.swift index 4fb3ead..2d44707 100644 --- a/Sources/Rainmaker/Requests/Requesting.swift +++ b/Sources/Rainmaker/Requests/Requesting.swift @@ -6,7 +6,7 @@ import Foundation /// /// Features of `URLSession` defined as a mockable protocol for tests. /// -protocol Requesting: Sendable { +public protocol Requesting: Sendable { func data(for request: URLRequest) async throws -> (Data, URLResponse) func download(for request: URLRequest, delegate: (any URLSessionTaskDelegate)?) async throws -> (URL, URLResponse) } diff --git a/Sources/Rainmaker/Server.swift b/Sources/Rainmaker/Server.swift index b8bfb6e..e6f8982 100644 --- a/Sources/Rainmaker/Server.swift +++ b/Sources/Rainmaker/Server.swift @@ -330,14 +330,10 @@ public final class Server { /// - address: HTTP address of the Nextcloud host. /// - password: In most cases, this is the app password and not the account password. /// - user: The Nextcloud user name used to identify as. + /// - session: A ``Requesting`` object (e.g. a `URLSession`) to use for network requests. Defaults to a new ephemeral `URLSession`. /// - userAgent: The user agent to report as in HTTP request headers. /// - public convenience init(address: URL, password: String? = nil, user: String? = nil, userAgent: String = "Rainmaker") { - let session = URLSession(configuration: .ephemeral) - self.init(address: address, password: password, user: user, session: session, userAgent: userAgent) - } - - init(address: URL, password: String? = nil, user: String? = nil, session: any Requesting, userAgent: String) { + public init(address: URL, password: String? = nil, user: String? = nil, session: any Requesting = URLSession(configuration: .ephemeral), userAgent: String = "Rainmaker") { self.address = address jsonDecoder = JSONDecoder() self.password = password