1414
1515#if canImport(FoundationEssentials)
1616import FoundationEssentials
17- #else
17+ #else // canImport(FoundationEssentials)
1818import Foundation
19- #endif
20-
2119#if canImport(CoreFoundation)
22- import Foundation
2320import CoreFoundation
2421#endif // canImport(CoreFoundation)
22+ #endif // canImport(FoundationEssentials)
2523
2624extension HTTPRequest {
2725 /// The URL of the request synthesized from the scheme, authority, and path pseudo header
@@ -92,7 +90,7 @@ extension URL {
9290 buffer. append ( contentsOf: authority)
9391 buffer. append ( contentsOf: path)
9492
95- #if canImport(CoreFoundation)
93+ #if !canImport(FoundationEssentials) && canImport(CoreFoundation)
9694 if let url = buffer. withUnsafeBytes ( { buffer in
9795 CFURLCreateAbsoluteURLWithBytes (
9896 kCFAllocatorDefault,
@@ -107,14 +105,14 @@ extension URL {
107105 } else {
108106 return nil
109107 }
110- #else // canImport(CoreFoundation)
108+ #else // !canImport(FoundationEssentials) && canImport(CoreFoundation)
111109 // This initializer does not preserve WHATWG URLs
112110 self . init ( string: String ( decoding: buffer, as: UTF8 . self) )
113- #endif // canImport(CoreFoundation)
111+ #endif // !canImport(FoundationEssentials) && canImport(CoreFoundation)
114112 }
115113
116114 fileprivate var httpRequestComponents : ( scheme: [ UInt8 ] , authority: [ UInt8 ] ? , path: [ UInt8 ] ) {
117- #if canImport(CoreFoundation)
115+ #if !canImport(FoundationEssentials) && canImport(CoreFoundation)
118116 // CFURL parser based on byte ranges does not unnecessarily percent-encode WHATWG URL
119117 let url = unsafeBitCast ( self . absoluteURL as NSURL , to: CFURL . self)
120118 let length = CFURLGetBytes ( url, nil , 0 )
@@ -167,7 +165,7 @@ extension URL {
167165 }
168166 return ( scheme, authority, path)
169167 }
170- #else // canImport(CoreFoundation)
168+ #else // !canImport(FoundationEssentials) && canImport(CoreFoundation)
171169 guard let components = URLComponents ( url: self , resolvingAgainstBaseURL: true ) ,
172170 let urlString = components. string
173171 else {
@@ -213,6 +211,6 @@ extension URL {
213211 }
214212 }
215213 return ( scheme, authority, path)
216- #endif // canImport(CoreFoundation)
214+ #endif // !canImport(FoundationEssentials) && canImport(CoreFoundation)
217215 }
218216}
0 commit comments