From e3eab0800db4596dea046d90ad5495f0e527a39d Mon Sep 17 00:00:00 2001 From: Tobias Haeberle Date: Fri, 27 Dec 2024 09:31:53 +0100 Subject: [PATCH] import FoundationEssentials instead of Foundation when available --- .../AsyncAwait/HTTPClientRequest+auth.swift | 4 ++++ Sources/AsyncHTTPClient/BasicAuth.swift | 7 ++++++- Sources/AsyncHTTPClient/FoundationExtensions.swift | 4 ++++ Sources/AsyncHTTPClient/HTTPClient.swift | 7 ++++++- Sources/AsyncHTTPClient/HTTPHandler.swift | 7 ++++++- Tests/AsyncHTTPClientTests/HTTPClientCookieTests.swift | 7 ++++++- Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift | 7 ++++++- 7 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest+auth.swift b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest+auth.swift index 106a8f76b..ca9aba356 100644 --- a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest+auth.swift +++ b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest+auth.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) extension HTTPClientRequest { diff --git a/Sources/AsyncHTTPClient/BasicAuth.swift b/Sources/AsyncHTTPClient/BasicAuth.swift index 3e69f8277..2a0260eb7 100644 --- a/Sources/AsyncHTTPClient/BasicAuth.swift +++ b/Sources/AsyncHTTPClient/BasicAuth.swift @@ -12,9 +12,14 @@ // //===----------------------------------------------------------------------===// -import Foundation import NIOHTTP1 +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + /// Generates base64 encoded username + password for http basic auth. /// /// - Parameters: diff --git a/Sources/AsyncHTTPClient/FoundationExtensions.swift b/Sources/AsyncHTTPClient/FoundationExtensions.swift index 452cb7b13..79f679f37 100644 --- a/Sources/AsyncHTTPClient/FoundationExtensions.swift +++ b/Sources/AsyncHTTPClient/FoundationExtensions.swift @@ -15,7 +15,11 @@ // Extensions which provide better ergonomics when using Foundation types, // or by using Foundation APIs. +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif extension HTTPClient.Cookie { /// The cookie's expiration date. diff --git a/Sources/AsyncHTTPClient/HTTPClient.swift b/Sources/AsyncHTTPClient/HTTPClient.swift index f1655c7c5..f14303a3e 100644 --- a/Sources/AsyncHTTPClient/HTTPClient.swift +++ b/Sources/AsyncHTTPClient/HTTPClient.swift @@ -13,7 +13,6 @@ //===----------------------------------------------------------------------===// import Atomics -import Foundation import Logging import NIOConcurrencyHelpers import NIOCore @@ -24,6 +23,12 @@ import NIOSSL import NIOTLS import NIOTransportServices +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + extension Logger { private func requestInfo(_ request: HTTPClient.Request) -> Logger.Metadata.Value { "\(request.method) \(request.url)" diff --git a/Sources/AsyncHTTPClient/HTTPHandler.swift b/Sources/AsyncHTTPClient/HTTPHandler.swift index 0f061fbe6..1032a037f 100644 --- a/Sources/AsyncHTTPClient/HTTPHandler.swift +++ b/Sources/AsyncHTTPClient/HTTPHandler.swift @@ -13,7 +13,6 @@ //===----------------------------------------------------------------------===// import Algorithms -import Foundation import Logging import NIOConcurrencyHelpers import NIOCore @@ -21,6 +20,12 @@ import NIOHTTP1 import NIOPosix import NIOSSL +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + extension HTTPClient { /// A request body. public struct Body { diff --git a/Tests/AsyncHTTPClientTests/HTTPClientCookieTests.swift b/Tests/AsyncHTTPClientTests/HTTPClientCookieTests.swift index fa9abb9d8..8fc4f0bfd 100644 --- a/Tests/AsyncHTTPClientTests/HTTPClientCookieTests.swift +++ b/Tests/AsyncHTTPClientTests/HTTPClientCookieTests.swift @@ -14,9 +14,14 @@ import AsyncHTTPClient import CAsyncHTTPClient -import Foundation import XCTest +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + class HTTPClientCookieTests: XCTestCase { func testCookie() { let v = diff --git a/Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift b/Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift index da2046b81..fa5ebab49 100644 --- a/Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift +++ b/Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift @@ -13,7 +13,6 @@ //===----------------------------------------------------------------------===// import Atomics -import Foundation import Logging import NIOConcurrencyHelpers import NIOCore @@ -31,6 +30,12 @@ import XCTest @testable import AsyncHTTPClient +#if canImport(FoundationEssentials) +import FoundationEssentials +#else +import Foundation +#endif + #if canImport(xlocale) import xlocale #elseif canImport(locale_h)