@@ -1149,14 +1149,27 @@ struct CollectEverythingLogHandler: LogHandler {
1149
1149
}
1150
1150
}
1151
1151
1152
- class StreamDelegate : HTTPClientResponseDelegate {
1152
+ /// A ``HTTPClientResponseDelegate`` that buffers the incoming response parts for the consumer. The consumer can
1153
+ /// consume the bytes by calling ``next()`` on the delegate.
1154
+ ///
1155
+ /// The sole purpose of this class is to enable straight-line stream tests.
1156
+ class ResponseStreamDelegate : HTTPClientResponseDelegate {
1153
1157
typealias Response = Void
1154
1158
1155
1159
enum State {
1160
+ /// The delegate is in the idle state. There are no http response parts to be buffered
1161
+ /// and the consumer did not signal a demand. Transitions to all other states are allowed.
1156
1162
case idle
1163
+ /// The consumer has signaled a demand for more bytes, but none where available. Can
1164
+ /// transition to `.idle` (when new bytes arrive), `.finished` (when the stream finishes or fails)
1157
1165
case waitingForBytes( EventLoopPromise < ByteBuffer ? > )
1166
+ /// The consumer has signaled no further demand but bytes keep arriving. Valid transitions
1167
+ /// to `.idle` (when bytes are consumed), `.finished` (when bytes are consumed, and the
1168
+ /// stream has ended), `.failed` (if an error is forwarded)
1158
1169
case buffering( ByteBuffer , done: Bool )
1170
+ /// Stores an error for consumption. Valid transitions are: `.finished`, when the error was consumed.
1159
1171
case failed( Error )
1172
+ /// The stream has finished and all bytes or errors where consumed.
1160
1173
case finished
1161
1174
}
1162
1175
@@ -1207,24 +1220,24 @@ class StreamDelegate: HTTPClientResponseDelegate {
1207
1220
// MARK: HTTPClientResponseDelegate
1208
1221
1209
1222
func didSendRequestHead( task: HTTPClient . Task < Response > , _ head: HTTPRequestHead ) {
1210
- XCTAssert ( self . eventLoop. inEventLoop )
1223
+ self . eventLoop. preconditionInEventLoop ( )
1211
1224
}
1212
1225
1213
1226
func didSendRequestPart( task: HTTPClient . Task < Response > , _ part: IOData ) {
1214
- XCTAssert ( self . eventLoop. inEventLoop )
1227
+ self . eventLoop. preconditionInEventLoop ( )
1215
1228
}
1216
1229
1217
1230
func didSendRequest( task: HTTPClient . Task < Response > ) {
1218
- XCTAssert ( self . eventLoop. inEventLoop )
1231
+ self . eventLoop. preconditionInEventLoop ( )
1219
1232
}
1220
1233
1221
1234
func didReceiveHead( task: HTTPClient . Task < Response > , _ head: HTTPResponseHead ) -> EventLoopFuture < Void > {
1222
- XCTAssert ( self . eventLoop. inEventLoop )
1235
+ self . eventLoop. preconditionInEventLoop ( )
1223
1236
return task. eventLoop. makeSucceededVoidFuture ( )
1224
1237
}
1225
1238
1226
1239
func didReceiveBodyPart( task: HTTPClient . Task < Response > , _ buffer: ByteBuffer ) -> EventLoopFuture < Void > {
1227
- XCTAssert ( self . eventLoop. inEventLoop )
1240
+ self . eventLoop. preconditionInEventLoop ( )
1228
1241
1229
1242
switch self . state {
1230
1243
case . idle:
@@ -1244,7 +1257,7 @@ class StreamDelegate: HTTPClientResponseDelegate {
1244
1257
}
1245
1258
1246
1259
func didReceiveError( task: HTTPClient . Task < Response > , _ error: Error ) {
1247
- XCTAssert ( self . eventLoop. inEventLoop )
1260
+ self . eventLoop. preconditionInEventLoop ( )
1248
1261
1249
1262
switch self . state {
1250
1263
case . idle:
@@ -1260,7 +1273,7 @@ class StreamDelegate: HTTPClientResponseDelegate {
1260
1273
}
1261
1274
1262
1275
func didFinishRequest( task: HTTPClient . Task < Response > ) throws {
1263
- XCTAssert ( self . eventLoop. inEventLoop )
1276
+ self . eventLoop. preconditionInEventLoop ( )
1264
1277
1265
1278
switch self . state {
1266
1279
case . idle:
0 commit comments