@@ -121,25 +121,9 @@ public final class HTTPBody: @unchecked Sendable {
121
121
/// The underlying byte chunk type.
122
122
public typealias ByteChunk = ArraySlice < UInt8 >
123
123
124
- /// Describes how many times the provided sequence can be iterated.
125
- public enum IterationBehavior : Sendable {
126
-
127
- /// The input sequence can only be iterated once.
128
- ///
129
- /// If a retry or a redirect is encountered, fail the call with
130
- /// a descriptive error.
131
- case single
132
-
133
- /// The input sequence can be iterated multiple times.
134
- ///
135
- /// Supports retries and redirects, as a new iterator is created each
136
- /// time.
137
- case multiple
138
- }
139
-
140
- /// The body's iteration behavior, which controls how many times
124
+ /// The iteration behavior, which controls how many times
141
125
/// the input sequence can be iterated.
142
- public let iterationBehavior : IterationBehavior
126
+ public let iterationBehavior : OpenAPIRuntime . IterationBehavior
143
127
144
128
/// Describes the total length of the body, if known.
145
129
public enum Length : Sendable , Equatable {
@@ -155,7 +139,7 @@ public final class HTTPBody: @unchecked Sendable {
155
139
public let length : Length
156
140
157
141
/// The underlying type-erased async sequence.
158
- private let sequence : BodySequence
142
+ private let sequence : AnySequence < ByteChunk >
159
143
160
144
/// A lock for shared mutable state.
161
145
private let lock : NSLock = {
@@ -205,7 +189,11 @@ public final class HTTPBody: @unchecked Sendable {
205
189
/// length of all the byte chunks.
206
190
/// - iterationBehavior: The sequence's iteration behavior, which
207
191
/// indicates whether the sequence can be iterated multiple times.
208
- @usableFromInline init ( _ sequence: BodySequence , length: Length , iterationBehavior: IterationBehavior ) {
192
+ @usableFromInline init (
193
+ _ sequence: AnySequence < ByteChunk > ,
194
+ length: Length ,
195
+ iterationBehavior: OpenAPIRuntime . IterationBehavior
196
+ ) {
209
197
self . sequence = sequence
210
198
self . length = length
211
199
self . iterationBehavior = iterationBehavior
@@ -220,7 +208,7 @@ public final class HTTPBody: @unchecked Sendable {
220
208
@usableFromInline convenience init (
221
209
_ byteChunks: some Sequence < ByteChunk > & Sendable ,
222
210
length: Length ,
223
- iterationBehavior: IterationBehavior
211
+ iterationBehavior: OpenAPIRuntime . IterationBehavior
224
212
) {
225
213
self . init (
226
214
. init( WrappedSyncSequence ( sequence: byteChunks) ) ,
@@ -281,7 +269,7 @@ extension HTTPBody {
281
269
@inlinable public convenience init (
282
270
_ bytes: some Sequence < UInt8 > & Sendable ,
283
271
length: Length ,
284
- iterationBehavior: IterationBehavior
272
+ iterationBehavior: OpenAPIRuntime . IterationBehavior
285
273
) { self . init ( [ ArraySlice ( bytes) ] , length: length, iterationBehavior: iterationBehavior) }
286
274
287
275
/// Creates a new body with the provided byte collection.
@@ -323,7 +311,7 @@ extension HTTPBody {
323
311
@inlinable public convenience init < Bytes: AsyncSequence > (
324
312
_ sequence: Bytes ,
325
313
length: HTTPBody . Length ,
326
- iterationBehavior: IterationBehavior
314
+ iterationBehavior: OpenAPIRuntime . IterationBehavior
327
315
) where Bytes. Element == ByteChunk , Bytes: Sendable {
328
316
self . init ( . init( sequence) , length: length, iterationBehavior: iterationBehavior)
329
317
}
@@ -337,7 +325,7 @@ extension HTTPBody {
337
325
@inlinable public convenience init < Bytes: AsyncSequence > (
338
326
_ sequence: Bytes ,
339
327
length: HTTPBody . Length ,
340
- iterationBehavior: IterationBehavior
328
+ iterationBehavior: OpenAPIRuntime . IterationBehavior
341
329
) where Bytes: Sendable , Bytes. Element: Sequence & Sendable , Bytes. Element. Element == UInt8 {
342
330
self . init ( sequence. map { ArraySlice ( $0) } , length: length, iterationBehavior: iterationBehavior)
343
331
}
@@ -356,7 +344,7 @@ extension HTTPBody: AsyncSequence {
356
344
public func makeAsyncIterator( ) -> AsyncIterator {
357
345
// The crash on error is intentional here.
358
346
try ! tryToMarkIteratorCreated ( )
359
- return sequence. makeAsyncIterator ( )
347
+ return . init ( sequence. makeAsyncIterator ( ) )
360
348
}
361
349
}
362
350
@@ -482,7 +470,7 @@ extension HTTPBody {
482
470
@inlinable public convenience init < Strings: AsyncSequence > (
483
471
_ sequence: Strings ,
484
472
length: HTTPBody . Length ,
485
- iterationBehavior: IterationBehavior
473
+ iterationBehavior: OpenAPIRuntime . IterationBehavior
486
474
) where Strings. Element: StringProtocol & Sendable , Strings: Sendable {
487
475
self . init ( . init( sequence. map { ByteChunk . init ( $0) } ) , length: length, iterationBehavior: iterationBehavior)
488
476
}
@@ -583,83 +571,3 @@ extension HTTPBody {
583
571
public mutating func next( ) async throws -> Element ? { try await produceNext ( ) }
584
572
}
585
573
}
586
-
587
- extension HTTPBody {
588
-
589
- /// A type-erased async sequence that wraps input sequences.
590
- @usableFromInline struct BodySequence : AsyncSequence , Sendable {
591
-
592
- /// The type of the type-erased iterator.
593
- @usableFromInline typealias AsyncIterator = HTTPBody . Iterator
594
-
595
- /// The byte chunk element type.
596
- @usableFromInline typealias Element = ByteChunk
597
-
598
- /// A closure that produces a new iterator.
599
- @usableFromInline let produceIterator : @Sendable ( ) -> AsyncIterator
600
-
601
- /// Creates a new sequence.
602
- /// - Parameter sequence: The input sequence to type-erase.
603
- @inlinable init < Bytes: AsyncSequence > ( _ sequence: Bytes ) where Bytes. Element == Element , Bytes: Sendable {
604
- self . produceIterator = { . init( sequence. makeAsyncIterator ( ) ) }
605
- }
606
-
607
- @usableFromInline func makeAsyncIterator( ) -> AsyncIterator { produceIterator ( ) }
608
- }
609
-
610
- /// An async sequence wrapper for a sync sequence.
611
- @usableFromInline struct WrappedSyncSequence < Bytes: Sequence > : AsyncSequence , Sendable
612
- where Bytes. Element == ByteChunk , Bytes. Iterator. Element == ByteChunk , Bytes: Sendable {
613
-
614
- /// The type of the iterator.
615
- @usableFromInline typealias AsyncIterator = Iterator
616
-
617
- /// The byte chunk element type.
618
- @usableFromInline typealias Element = ByteChunk
619
-
620
- /// An iterator type that wraps a sync sequence iterator.
621
- @usableFromInline struct Iterator : AsyncIteratorProtocol {
622
-
623
- /// The byte chunk element type.
624
- @usableFromInline typealias Element = ByteChunk
625
-
626
- /// The underlying sync sequence iterator.
627
- var iterator : any IteratorProtocol < Element >
628
-
629
- @usableFromInline mutating func next( ) async throws -> HTTPBody . ByteChunk ? { iterator. next ( ) }
630
- }
631
-
632
- /// The underlying sync sequence.
633
- @usableFromInline let sequence : Bytes
634
-
635
- /// Creates a new async sequence with the provided sync sequence.
636
- /// - Parameter sequence: The sync sequence to wrap.
637
- @inlinable init ( sequence: Bytes ) { self . sequence = sequence }
638
-
639
- @usableFromInline func makeAsyncIterator( ) -> Iterator { Iterator ( iterator: sequence. makeIterator ( ) ) }
640
- }
641
-
642
- /// An empty async sequence.
643
- @usableFromInline struct EmptySequence : AsyncSequence , Sendable {
644
-
645
- /// The type of the empty iterator.
646
- @usableFromInline typealias AsyncIterator = EmptyIterator
647
-
648
- /// The byte chunk element type.
649
- @usableFromInline typealias Element = ByteChunk
650
-
651
- /// An async iterator of an empty sequence.
652
- @usableFromInline struct EmptyIterator : AsyncIteratorProtocol {
653
-
654
- /// The byte chunk element type.
655
- @usableFromInline typealias Element = ByteChunk
656
-
657
- @usableFromInline mutating func next( ) async throws -> HTTPBody . ByteChunk ? { nil }
658
- }
659
-
660
- /// Creates a new empty async sequence.
661
- @inlinable init ( ) { }
662
-
663
- @usableFromInline func makeAsyncIterator( ) -> EmptyIterator { EmptyIterator ( ) }
664
- }
665
- }
0 commit comments