-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add HTTPClientFoundation combining Body and Data into one associatedtype. remove associatedType
- Loading branch information
1 parent
f9a647b
commit f0d99d1
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Foundation | ||
import HTTPTypes | ||
|
||
public protocol HTTPClientProtocol { | ||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | ||
func execute(for request: HTTPRequest, from body: Data?) async throws -> (Data, HTTPResponse) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Foundation | ||
import HTTPClient | ||
import HTTPTypes | ||
import HTTPTypesFoundation | ||
|
||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS) || compiler(>=6) | ||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | ||
extension URLSession: HTTPClientProtocol { | ||
public func execute( | ||
for request: HTTPRequest, | ||
from bodyData: Data? | ||
) async throws -> (Data, HTTPResponse) { | ||
if let bodyData { | ||
try await self.upload(for: request, from: bodyData) | ||
} else { | ||
try await self.data(for: request) | ||
} | ||
} | ||
} | ||
|
||
extension HTTPClientProtocol where Self == URLSession { | ||
public static func urlSession(_ urlSession: Self) -> Self { | ||
return urlSession | ||
} | ||
} | ||
#endif |