Skip to content

Commit

Permalink
0.34.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Mar 10, 2024
1 parent 1910c9f commit 1f6a199
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ import PackageDescription
let package = Package(
name: "SomeProject",
dependencies: [
.package(url: "https://github.com/dankinsoid/swift-networking.git", from: "0.33.0")
.package(url: "https://github.com/dankinsoid/swift-networking.git", from: "0.34.0")
],
targets: [
.target(
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftNetworking/Modifiers/RedirectModifier.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation

#if !canImport(FoundationNetworking)
public extension NetworkClient.Configs {

/// The redirect behaviour for the client. Default is `.follow`.
Expand All @@ -17,3 +18,4 @@ public extension NetworkClient {
configs(\.redirectBehaviour, behaviour)
}
}
#endif
10 changes: 10 additions & 0 deletions Sources/SwiftNetworking/Modifiers/URLSessionModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,44 @@ public extension NetworkClient.Configs {
/// Underlying URLSession of the client.
var urlSession: URLSession {
let session = URLSession.networkClient
#if !canImport(FoundationNetworking)
SessionDelegateProxy.shared.configs = self
#endif
return session
}

#if !canImport(FoundationNetworking)
/// The delegate for the URLSession of the client.
var urlSessionDelegate: URLSessionDelegate? {
get { self[\.urlSessionDelegate] ?? nil }
set { self[\.urlSessionDelegate] = newValue }
}
#endif
}

#if !canImport(FoundationNetworking)
public extension NetworkClient {

/// Sets the URLSession delegate for the client.
func urlSession(delegate: URLSessionDelegate?) -> Self {
configs(\.urlSessionDelegate, delegate)
}
}
#endif

private extension URLSession {

static var networkClient: URLSession = {
#if !canImport(FoundationNetworking)
var configs = URLSessionConfiguration.default
configs.headers = .default
return URLSession(
configuration: configs,
delegate: SessionDelegateProxy.shared,
delegateQueue: nil
)
#else
return URLSession.shared
#endif
}()
}
5 changes: 2 additions & 3 deletions Sources/SwiftNetworking/Utils/URLSessionDelegateWrapper.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
#if !canImport(FoundationNetworking)

final class SessionDelegateProxy: NSObject, URLSessionDelegate {

Expand Down Expand Up @@ -69,3 +67,4 @@ extension SessionDelegateProxy: URLSessionDownloadDelegate {
extension SessionDelegateProxy: URLSessionStreamDelegate {}

extension SessionDelegateProxy: URLSessionWebSocketDelegate {}
#endif

0 comments on commit 1f6a199

Please sign in to comment.