From a6dafc2b1751181e38e9d6f7616d8a2dc3e1a4d2 Mon Sep 17 00:00:00 2001 From: Leif Date: Wed, 3 Apr 2024 17:13:11 -0600 Subject: [PATCH] Add optional delegate to network --- Sources/Network/Network.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/Network/Network.swift b/Sources/Network/Network.swift index ea62e49..1d50193 100644 --- a/Sources/Network/Network.swift +++ b/Sources/Network/Network.swift @@ -2,7 +2,11 @@ import Foundation /// A class that implements the `Networking` protocol to perform network requests using URLSession. open class Network: Networking { - public init() { } + public weak var delegate: URLSessionTaskDelegate? + + public init(delegate: URLSessionTaskDelegate? = nil) { + self.delegate = delegate + } open func request( for url: URL, @@ -17,7 +21,10 @@ open class Network: Networking { request.httpBody = body return DataResponse( - try await URLSession.shared.data(for: request) + try await URLSession.shared.data( + for: request, + delegate: delegate + ) ) }