From 268889262a2e265abfc55992b9df9bdf264ca30a Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Mon, 7 Feb 2022 17:40:10 +0100 Subject: [PATCH] Make async/await API public --- .../AsyncAwait/HTTPClient+execute.swift | 4 +-- .../AsyncAwait/HTTPClient+shutdown.swift | 2 +- .../AsyncAwait/HTTPClientRequest.swift | 32 +++++++++---------- .../AsyncAwait/HTTPClientResponse.swift | 20 ++++++------ 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift index d8f8d0a5c..043ad510b 100644 --- a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift +++ b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift @@ -27,7 +27,7 @@ extension HTTPClient { /// - deadline: Point in time by which the request must complete. /// - logger: The logger to use for this request. /// - Returns: The response to the request. Note that the `body` of the response may not yet have been fully received. - func execute( + public func execute( _ request: HTTPClientRequest, deadline: NIODeadline, logger: Logger? = nil @@ -52,7 +52,7 @@ extension HTTPClient { /// - timeout: time the the request has to complete. /// - logger: The logger to use for this request. /// - Returns: The response to the request. Note that the `body` of the response may not yet have been fully received. - func execute( + public func execute( _ request: HTTPClientRequest, timeout: TimeAmount, logger: Logger? = nil diff --git a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+shutdown.swift b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+shutdown.swift index 36dadd2a7..4e7090dbf 100644 --- a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+shutdown.swift +++ b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+shutdown.swift @@ -17,7 +17,7 @@ extension HTTPClient { /// Shuts down the client and `EventLoopGroup` if it was created by the client. @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) - func shutdown() async throws { + public func shutdown() async throws { try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in self.shutdown { error in switch error { diff --git a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest.swift b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest.swift index 193a1618d..cfab828a0 100644 --- a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest.swift +++ b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest.swift @@ -17,14 +17,14 @@ import NIOCore import NIOHTTP1 @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) -struct HTTPClientRequest { - var url: String - var method: HTTPMethod - var headers: HTTPHeaders +public struct HTTPClientRequest { + public var url: String + public var method: HTTPMethod + public var headers: HTTPHeaders - var body: Body? + public var body: Body? - init(url: String) { + public init(url: String) { self.url = url self.method = .GET self.headers = .init() @@ -34,7 +34,7 @@ struct HTTPClientRequest { @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) extension HTTPClientRequest { - struct Body { + public struct Body { @usableFromInline internal enum Mode { case asyncSequence(length: RequestBodyLength, (ByteBufferAllocator) async throws -> ByteBuffer?) @@ -54,12 +54,12 @@ extension HTTPClientRequest { @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) extension HTTPClientRequest.Body { - static func bytes(_ byteBuffer: ByteBuffer) -> Self { + public static func bytes(_ byteBuffer: ByteBuffer) -> Self { self.init(.byteBuffer(byteBuffer)) } @inlinable - static func bytes( + public static func bytes( _ bytes: Bytes ) -> Self where Bytes.Element == UInt8 { self.init(.sequence( @@ -76,7 +76,7 @@ extension HTTPClientRequest.Body { } @inlinable - static func bytes( + public static func bytes( _ bytes: Bytes, length: Length ) -> Self where Bytes.Element == UInt8 { @@ -94,7 +94,7 @@ extension HTTPClientRequest.Body { } @inlinable - static func bytes( + public static func bytes( _ bytes: Bytes, length: Length ) -> Self where Bytes.Element == UInt8 { @@ -112,7 +112,7 @@ extension HTTPClientRequest.Body { } @inlinable - static func stream( + public static func stream( _ sequenceOfBytes: SequenceOfBytes, length: Length ) -> Self where SequenceOfBytes.Element == ByteBuffer { @@ -124,7 +124,7 @@ extension HTTPClientRequest.Body { } @inlinable - static func stream( + public static func stream( _ bytes: Bytes, length: Length ) -> Self where Bytes.Element == UInt8 { @@ -157,11 +157,11 @@ extension Optional where Wrapped == HTTPClientRequest.Body { @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) extension HTTPClientRequest.Body { - struct Length { + public struct Length { /// size of the request body is not known before starting the request - static let unknown: Self = .init(storage: .unknown) + public static let unknown: Self = .init(storage: .unknown) /// size of the request body is fixed and exactly `count` bytes - static func known(_ count: Int) -> Self { + public static func known(_ count: Int) -> Self { .init(storage: .known(count)) } diff --git a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift index 58f71979a..52f03089b 100644 --- a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift +++ b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift @@ -17,13 +17,13 @@ import NIOCore import NIOHTTP1 @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) -struct HTTPClientResponse { - var version: HTTPVersion - var status: HTTPResponseStatus - var headers: HTTPHeaders - var body: Body +public struct HTTPClientResponse { + public var version: HTTPVersion + public var status: HTTPResponseStatus + public var headers: HTTPHeaders + public var body: Body - struct Body { + public struct Body { private let bag: Transaction private let reference: ResponseRef @@ -48,21 +48,21 @@ struct HTTPClientResponse { @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) extension HTTPClientResponse.Body: AsyncSequence { - typealias Element = AsyncIterator.Element + public typealias Element = AsyncIterator.Element - struct AsyncIterator: AsyncIteratorProtocol { + public struct AsyncIterator: AsyncIteratorProtocol { private let stream: IteratorStream fileprivate init(stream: IteratorStream) { self.stream = stream } - mutating func next() async throws -> ByteBuffer? { + public mutating func next() async throws -> ByteBuffer? { try await self.stream.next() } } - func makeAsyncIterator() -> AsyncIterator { + public func makeAsyncIterator() -> AsyncIterator { AsyncIterator(stream: IteratorStream(bag: self.bag)) } }