Skip to content

Commit e249213

Browse files
committed
Make all required types for async/await public
and add nescary @inlinable/@usableFromInlinable for generic `HTTPClientReuqest.Body` builder metods.
1 parent d372bdc commit e249213

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extension HTTPClient {
2727
/// - deadline: Point in time by which the request must complete.
2828
/// - logger: The logger to use for this request.
2929
/// - Returns: The response to the request. Note that the `body` of the response may not yet have been fully received.
30-
func execute(
30+
public func execute(
3131
_ request: HTTPClientRequest,
3232
deadline: NIODeadline,
3333
logger: Logger

Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest.swift

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import NIOCore
1717
import NIOHTTP1
1818

1919
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
20-
struct HTTPClientRequest {
21-
var url: String
22-
var method: HTTPMethod
23-
var headers: HTTPHeaders
20+
public struct HTTPClientRequest {
21+
public var url: String
22+
public var method: HTTPMethod
23+
public var headers: HTTPHeaders
2424

25-
var body: Body?
25+
public var body: Body?
2626

27-
init(url: String) {
27+
public init(url: String) {
2828
self.url = url
2929
self.method = .GET
3030
self.headers = .init()
@@ -34,29 +34,32 @@ struct HTTPClientRequest {
3434

3535
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
3636
extension HTTPClientRequest {
37-
struct Body {
37+
public struct Body {
38+
@usableFromInline
3839
internal enum Mode {
3940
case asyncSequence(length: Int?, (ByteBufferAllocator) async throws -> ByteBuffer?)
4041
case sequence(length: Int?, canBeConsumedMultipleTimes: Bool, (ByteBufferAllocator) -> ByteBuffer)
4142
case byteBuffer(ByteBuffer)
4243
}
4344

44-
var mode: Mode
45+
@usableFromInline
46+
internal var mode: Mode
4547

46-
private init(_ mode: Mode) {
48+
@inlinable
49+
internal init(_ mode: Mode) {
4750
self.mode = mode
4851
}
4952
}
5053
}
5154

5255
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
5356
extension HTTPClientRequest.Body {
54-
static func byteBuffer(_ byteBuffer: ByteBuffer) -> Self {
57+
public static func byteBuffer(_ byteBuffer: ByteBuffer) -> Self {
5558
self.init(.byteBuffer(byteBuffer))
5659
}
5760

5861
@inlinable
59-
static func bytes<Bytes: Sequence>(
62+
public static func bytes<Bytes: Sequence>(
6063
length: Int?,
6164
_ bytes: Bytes
6265
) -> Self where Bytes.Element == UInt8 {
@@ -71,7 +74,7 @@ extension HTTPClientRequest.Body {
7174
}
7275

7376
@inlinable
74-
static func bytes<Bytes: Collection>(
77+
public static func bytes<Bytes: Collection>(
7578
length: Int?,
7679
_ bytes: Bytes
7780
) -> Self where Bytes.Element == UInt8 {
@@ -86,7 +89,7 @@ extension HTTPClientRequest.Body {
8689
}
8790

8891
@inlinable
89-
static func bytes<Bytes: RandomAccessCollection>(
92+
public static func bytes<Bytes: RandomAccessCollection>(
9093
_ bytes: Bytes
9194
) -> Self where Bytes.Element == UInt8 {
9295
self.init(.sequence(length: bytes.count, canBeConsumedMultipleTimes: true) { allocator in
@@ -100,7 +103,7 @@ extension HTTPClientRequest.Body {
100103
}
101104

102105
@inlinable
103-
static func stream<SequenceOfBytes: AsyncSequence>(
106+
public static func stream<SequenceOfBytes: AsyncSequence>(
104107
length: Int?,
105108
_ sequenceOfBytes: SequenceOfBytes
106109
) -> Self where SequenceOfBytes.Element == ByteBuffer {
@@ -112,7 +115,7 @@ extension HTTPClientRequest.Body {
112115
}
113116

114117
@inlinable
115-
static func stream<Bytes: AsyncSequence>(
118+
public static func stream<Bytes: AsyncSequence>(
116119
length: Int?,
117120
_ bytes: Bytes
118121
) -> Self where Bytes.Element == UInt8 {

Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import NIOCore
1717
import NIOHTTP1
1818

1919
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
20-
struct HTTPClientResponse {
21-
var version: HTTPVersion
22-
var status: HTTPResponseStatus
23-
var headers: HTTPHeaders
24-
var body: Body
20+
public struct HTTPClientResponse {
21+
public var version: HTTPVersion
22+
public var status: HTTPResponseStatus
23+
public var headers: HTTPHeaders
24+
public var body: Body
2525

26-
struct Body {
26+
public struct Body {
2727
private let bag: Transaction
2828
private let reference: ResponseRef
2929

@@ -48,25 +48,22 @@ struct HTTPClientResponse {
4848

4949
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
5050
extension HTTPClientResponse.Body: AsyncSequence {
51-
typealias Element = ByteBuffer
52-
typealias AsyncIterator = Iterator
53-
54-
struct Iterator: AsyncIteratorProtocol {
55-
typealias Element = ByteBuffer
51+
public typealias Element = AsyncIterator.Element
5652

53+
public struct AsyncIterator: AsyncIteratorProtocol {
5754
private let stream: IteratorStream
5855

5956
fileprivate init(stream: IteratorStream) {
6057
self.stream = stream
6158
}
6259

63-
func next() async throws -> ByteBuffer? {
60+
public func next() async throws -> ByteBuffer? {
6461
try await self.stream.next()
6562
}
6663
}
6764

68-
func makeAsyncIterator() -> Iterator {
69-
Iterator(stream: IteratorStream(bag: self.bag))
65+
public func makeAsyncIterator() -> AsyncIterator {
66+
AsyncIterator(stream: IteratorStream(bag: self.bag))
7067
}
7168
}
7269

0 commit comments

Comments
 (0)