@@ -45,14 +45,25 @@ public struct HTTPClientResponse: Sendable {
45
45
}
46
46
47
47
init (
48
- bag : Transaction ,
48
+ requestMethod : HTTPMethod ,
49
49
version: HTTPVersion ,
50
50
status: HTTPResponseStatus ,
51
51
headers: HTTPHeaders ,
52
- requestMethod : HTTPMethod
52
+ body : TransactionBody
53
53
) {
54
- let contentLength = HTTPClientResponse . expectedContentLength ( requestMethod: requestMethod, headers: headers, status: status)
55
- self . init ( version: version, status: status, headers: headers, body: . init( TransactionBody ( bag, expectedContentLength: contentLength) ) )
54
+ self . init (
55
+ version: version,
56
+ status: status,
57
+ headers: headers,
58
+ body: . init( . transaction(
59
+ body,
60
+ expectedContentLength: HTTPClientResponse . expectedContentLength (
61
+ requestMethod: requestMethod,
62
+ headers: headers,
63
+ status: status
64
+ )
65
+ ) )
66
+ )
56
67
}
57
68
}
58
69
@@ -94,8 +105,8 @@ extension HTTPClientResponse {
94
105
/// - Returns: the number of bytes collected over time
95
106
@inlinable public func collect( upTo maxBytes: Int ) async throws -> ByteBuffer {
96
107
switch self . storage {
97
- case . transaction( let transactionBody ) :
98
- if let contentLength = transactionBody . expectedContentLength {
108
+ case . transaction( _ , let expectedContentLength ) :
109
+ if let contentLength = expectedContentLength {
99
110
if contentLength > maxBytes {
100
111
throw NIOTooManyBytesError ( )
101
112
}
@@ -127,10 +138,19 @@ extension HTTPClientResponse {
127
138
}
128
139
}
129
140
141
+ @available ( macOS 10 . 15 , iOS 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
142
+ @usableFromInline
143
+ typealias TransactionBody = NIOThrowingAsyncSequenceProducer <
144
+ ByteBuffer ,
145
+ Error ,
146
+ NIOAsyncSequenceProducerBackPressureStrategies . HighLowWatermark ,
147
+ AnyAsyncSequenceProducerDelegate
148
+ >
149
+
130
150
@available ( macOS 10 . 15 , iOS 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
131
151
extension HTTPClientResponse . Body {
132
152
@usableFromInline enum Storage : Sendable {
133
- case transaction( TransactionBody )
153
+ case transaction( TransactionBody , expectedContentLength : Int ? )
134
154
case anyAsyncSequence( AnyAsyncSequence < ByteBuffer > )
135
155
}
136
156
}
@@ -141,7 +161,7 @@ extension HTTPClientResponse.Body.Storage: AsyncSequence {
141
161
142
162
@inlinable func makeAsyncIterator( ) -> AsyncIterator {
143
163
switch self {
144
- case . transaction( let transaction) :
164
+ case . transaction( let transaction, _ ) :
145
165
return . transaction( transaction. makeAsyncIterator ( ) )
146
166
case . anyAsyncSequence( let anyAsyncSequence) :
147
167
return . anyAsyncSequence( anyAsyncSequence. makeAsyncIterator ( ) )
@@ -172,10 +192,6 @@ extension HTTPClientResponse.Body.Storage.AsyncIterator: AsyncIteratorProtocol {
172
192
173
193
@available ( macOS 10 . 15 , iOS 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
174
194
extension HTTPClientResponse . Body {
175
- init ( _ body: TransactionBody ) {
176
- self . init ( storage: . transaction( body) )
177
- }
178
-
179
195
@inlinable init ( _ storage: Storage ) {
180
196
self . storage = storage
181
197
}
0 commit comments