diff --git a/Sources/HTTPTypes/HTTPRequest+URL.swift b/Sources/HTTPTypes/HTTPRequest+URL.swift index 75b655e..502763a 100644 --- a/Sources/HTTPTypes/HTTPRequest+URL.swift +++ b/Sources/HTTPTypes/HTTPRequest+URL.swift @@ -14,14 +14,12 @@ #if canImport(FoundationEssentials) import FoundationEssentials -#else +#else // canImport(FoundationEssentials) import Foundation -#endif - #if canImport(CoreFoundation) -import Foundation import CoreFoundation #endif // canImport(CoreFoundation) +#endif // canImport(FoundationEssentials) extension HTTPRequest { /// The URL of the request synthesized from the scheme, authority, and path pseudo header @@ -92,7 +90,7 @@ extension URL { buffer.append(contentsOf: authority) buffer.append(contentsOf: path) - #if canImport(CoreFoundation) + #if !canImport(FoundationEssentials) && canImport(CoreFoundation) if let url = buffer.withUnsafeBytes({ buffer in CFURLCreateAbsoluteURLWithBytes( kCFAllocatorDefault, @@ -107,14 +105,14 @@ extension URL { } else { return nil } - #else // canImport(CoreFoundation) + #else // !canImport(FoundationEssentials) && canImport(CoreFoundation) // This initializer does not preserve WHATWG URLs self.init(string: String(decoding: buffer, as: UTF8.self)) - #endif // canImport(CoreFoundation) + #endif // !canImport(FoundationEssentials) && canImport(CoreFoundation) } fileprivate var httpRequestComponents: (scheme: [UInt8], authority: [UInt8]?, path: [UInt8]) { - #if canImport(CoreFoundation) + #if !canImport(FoundationEssentials) && canImport(CoreFoundation) // CFURL parser based on byte ranges does not unnecessarily percent-encode WHATWG URL let url = unsafeBitCast(self.absoluteURL as NSURL, to: CFURL.self) let length = CFURLGetBytes(url, nil, 0) @@ -167,7 +165,7 @@ extension URL { } return (scheme, authority, path) } - #else // canImport(CoreFoundation) + #else // !canImport(FoundationEssentials) && canImport(CoreFoundation) guard let components = URLComponents(url: self, resolvingAgainstBaseURL: true), let urlString = components.string else { @@ -213,6 +211,6 @@ extension URL { } } return (scheme, authority, path) - #endif // canImport(CoreFoundation) + #endif // !canImport(FoundationEssentials) && canImport(CoreFoundation) } } diff --git a/Tests/HTTPTypesTests/HTTPTypesURLTests.swift b/Tests/HTTPTypesTests/HTTPTypesURLTests.swift index 69f0603..1088ae4 100644 --- a/Tests/HTTPTypesTests/HTTPTypesURLTests.swift +++ b/Tests/HTTPTypesTests/HTTPTypesURLTests.swift @@ -50,11 +50,11 @@ final class HTTPTypesURLTests: XCTestCase { let request5 = HTTPRequest(url: URL(string: "data:,Hello%2C%20World%21")!) XCTAssertEqual(request5.scheme, "data") XCTAssertNil(request5.authority) - #if canImport(CoreFoundation) + #if !canImport(FoundationEssentials) XCTAssertEqual(request5.path, "/") - #else // canImport(CoreFoundation) + #else // !canImport(FoundationEssentials) XCTAssertEqual(request5.path, ",Hello%2C%20World%21") - #endif // canImport(CoreFoundation) + #endif // !canImport(FoundationEssentials) XCTAssertNil(request5.url) }