Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions Sources/HTTPTypes/HTTPFields.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=6.0)
import Synchronization
#endif // compiler(>=6.0)

/// A collection of HTTP fields. It is used in `HTTPRequest` and `HTTPResponse`, and can also be
/// used as HTTP trailer fields.
Expand Down Expand Up @@ -109,7 +107,6 @@ public struct HTTPFields: Sendable, Hashable {
}
}

#if compiler(>=6.0)
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
private final class _StorageWithMutex: _Storage, @unchecked Sendable {
let mutex = Mutex<Void>(())
Expand All @@ -120,8 +117,8 @@ public struct HTTPFields: Sendable, Hashable {
}
}
}
#endif // compiler(>=6.0)

#if canImport(Darwin)
private final class _StorageWithNIOLock: _Storage, @unchecked Sendable {
let lock = LockStorage.create(value: ())

Expand All @@ -131,17 +128,18 @@ public struct HTTPFields: Sendable, Hashable {
}
}
}
#endif

private var _storage = {
#if compiler(>=6.0)
#if canImport(Darwin)
if #available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) {
_StorageWithMutex()
} else {
_StorageWithNIOLock()
}
#else // compiler(>=6.0)
_StorageWithNIOLock()
#endif // compiler(>=6.0)
#else
_StorageWithMutex()
#endif
}()

/// Create an empty list of HTTP fields
Expand Down
6 changes: 1 addition & 5 deletions Sources/HTTPTypesFoundation/URLSession+HTTPTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ private enum HTTPTypeConversionError: Error {

#endif

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || compiler(>=6) || (compiler(>=6) && os(visionOS))

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
extension URLSession {
/// Convenience method to load data using an `HTTPRequest`; creates and resumes a `URLSessionDataTask` internally.
Expand Down Expand Up @@ -129,7 +127,7 @@ extension URLSession {
return (location, response)
}

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || (compiler(>=6) && os(visionOS))
#if canImport(Darwin)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also replacing the Apple platform check with canImport(Darwin)

/// Returns a byte stream that conforms to AsyncSequence protocol.
///
/// - Parameter request: The `HTTPRequest` for which to load data.
Expand Down Expand Up @@ -200,5 +198,3 @@ extension URLSession {
return (data, response)
}
}

#endif