@@ -113,6 +113,9 @@ public final class NIOHTTP2Handler: ChannelDuplexHandler {
113
113
/// The maximum number of sequential CONTINUATION frames.
114
114
private let maximumSequentialContinuationFrames : Int
115
115
116
+ /// A delegate which is told about frames which have been written.
117
+ private let frameDelegate : NIOHTTP2FrameDelegate ?
118
+
116
119
@usableFromInline
117
120
internal var inboundStreamMultiplexer : InboundStreamMultiplexer ? {
118
121
self . inboundStreamMultiplexerState. multiplexer
@@ -242,7 +245,8 @@ public final class NIOHTTP2Handler: ChannelDuplexHandler {
242
245
maximumResetFrameCount: 200 ,
243
246
resetFrameCounterWindow: . seconds( 30 ) ,
244
247
maximumStreamErrorCount: 200 ,
245
- streamErrorCounterWindow: . seconds( 30 )
248
+ streamErrorCounterWindow: . seconds( 30 ) ,
249
+ frameDelegate: nil
246
250
)
247
251
}
248
252
@@ -280,7 +284,8 @@ public final class NIOHTTP2Handler: ChannelDuplexHandler {
280
284
maximumResetFrameCount: 200 ,
281
285
resetFrameCounterWindow: . seconds( 30 ) ,
282
286
maximumStreamErrorCount: 200 ,
283
- streamErrorCounterWindow: . seconds( 30 )
287
+ streamErrorCounterWindow: . seconds( 30 ) ,
288
+ frameDelegate: nil
284
289
)
285
290
286
291
}
@@ -295,6 +300,27 @@ public final class NIOHTTP2Handler: ChannelDuplexHandler {
295
300
mode: ParserMode ,
296
301
connectionConfiguration: ConnectionConfiguration = . init( ) ,
297
302
streamConfiguration: StreamConfiguration = . init( )
303
+ ) {
304
+ self . init (
305
+ mode: mode,
306
+ frameDelegate: nil ,
307
+ connectionConfiguration: connectionConfiguration,
308
+ streamConfiguration: streamConfiguration
309
+ )
310
+ }
311
+
312
+ /// Constructs a ``NIOHTTP2Handler``.
313
+ ///
314
+ /// - Parameters:
315
+ /// - mode: The mode for this handler, client or server.
316
+ /// - frameDelegate: A delegate which is notified about frames being written.
317
+ /// - connectionConfiguration: The settings that will be used when establishing the connection.
318
+ /// - streamConfiguration: The settings that will be used when establishing new streams.
319
+ public convenience init (
320
+ mode: ParserMode ,
321
+ frameDelegate: NIOHTTP2FrameDelegate ? ,
322
+ connectionConfiguration: ConnectionConfiguration = ConnectionConfiguration ( ) ,
323
+ streamConfiguration: StreamConfiguration = StreamConfiguration ( )
298
324
) {
299
325
self . init (
300
326
mode: mode,
@@ -310,7 +336,8 @@ public final class NIOHTTP2Handler: ChannelDuplexHandler {
310
336
maximumResetFrameCount: streamConfiguration. streamResetFrameRateLimit. maximumCount,
311
337
resetFrameCounterWindow: streamConfiguration. streamResetFrameRateLimit. windowLength,
312
338
maximumStreamErrorCount: streamConfiguration. streamErrorRateLimit. maximumCount,
313
- streamErrorCounterWindow: streamConfiguration. streamErrorRateLimit. windowLength
339
+ streamErrorCounterWindow: streamConfiguration. streamErrorRateLimit. windowLength,
340
+ frameDelegate: frameDelegate
314
341
)
315
342
}
316
343
@@ -328,7 +355,8 @@ public final class NIOHTTP2Handler: ChannelDuplexHandler {
328
355
maximumResetFrameCount: Int ,
329
356
resetFrameCounterWindow: TimeAmount ,
330
357
maximumStreamErrorCount: Int ,
331
- streamErrorCounterWindow: TimeAmount
358
+ streamErrorCounterWindow: TimeAmount ,
359
+ frameDelegate: NIOHTTP2FrameDelegate ?
332
360
) {
333
361
self . _eventLoop = eventLoop
334
362
self . stateMachine = HTTP2ConnectionStateMachine (
@@ -355,6 +383,7 @@ public final class NIOHTTP2Handler: ChannelDuplexHandler {
355
383
self . inboundStreamMultiplexerState = . uninitializedLegacy
356
384
self . maximumSequentialContinuationFrames = maximumSequentialContinuationFrames
357
385
self . glitchesMonitor = GlitchesMonitor ( maximumGlitches: maximumConnectionGlitches)
386
+ self . frameDelegate = frameDelegate
358
387
}
359
388
360
389
/// Constructs a ``NIOHTTP2Handler``.
@@ -391,7 +420,8 @@ public final class NIOHTTP2Handler: ChannelDuplexHandler {
391
420
resetFrameCounterWindow: TimeAmount = . seconds( 30 ) ,
392
421
maximumStreamErrorCount: Int = 200 ,
393
422
streamErrorCounterWindow: TimeAmount = . seconds( 30 ) ,
394
- maximumConnectionGlitches: Int = GlitchesMonitor . defaultMaximumGlitches
423
+ maximumConnectionGlitches: Int = GlitchesMonitor . defaultMaximumGlitches,
424
+ frameDelegate: NIOHTTP2FrameDelegate ? = nil
395
425
) {
396
426
self . stateMachine = HTTP2ConnectionStateMachine (
397
427
role: . init( mode) ,
@@ -418,6 +448,7 @@ public final class NIOHTTP2Handler: ChannelDuplexHandler {
418
448
self . inboundStreamMultiplexerState = . uninitializedLegacy
419
449
self . maximumSequentialContinuationFrames = maximumSequentialContinuationFrames
420
450
self . glitchesMonitor = GlitchesMonitor ( maximumGlitches: maximumConnectionGlitches)
451
+ self . frameDelegate = frameDelegate
421
452
}
422
453
423
454
public func handlerAdded( context: ChannelHandlerContext ) {
@@ -1067,6 +1098,11 @@ extension NIOHTTP2Handler {
1067
1098
return
1068
1099
}
1069
1100
1101
+ // Tell the delegate, if there is one.
1102
+ if let delegate = self . frameDelegate {
1103
+ delegate. wroteFrame ( frame)
1104
+ }
1105
+
1070
1106
// Ok, if we got here we're good to send data. We want to attach the promise to the latest write, not
1071
1107
// always the frame header.
1072
1108
self . wroteFrame = true
@@ -1391,7 +1427,8 @@ extension NIOHTTP2Handler {
1391
1427
maximumResetFrameCount: streamConfiguration. streamResetFrameRateLimit. maximumCount,
1392
1428
resetFrameCounterWindow: streamConfiguration. streamResetFrameRateLimit. windowLength,
1393
1429
maximumStreamErrorCount: streamConfiguration. streamErrorRateLimit. maximumCount,
1394
- streamErrorCounterWindow: streamConfiguration. streamErrorRateLimit. windowLength
1430
+ streamErrorCounterWindow: streamConfiguration. streamErrorRateLimit. windowLength,
1431
+ frameDelegate: nil
1395
1432
)
1396
1433
1397
1434
self . inboundStreamMultiplexerState = . uninitializedInline(
@@ -1408,6 +1445,7 @@ extension NIOHTTP2Handler {
1408
1445
connectionConfiguration: ConnectionConfiguration = . init( ) ,
1409
1446
streamConfiguration: StreamConfiguration = . init( ) ,
1410
1447
streamDelegate: NIOHTTP2StreamDelegate ? = nil ,
1448
+ frameDelegate: NIOHTTP2FrameDelegate ? ,
1411
1449
inboundStreamInitializerWithAnyOutput: @escaping StreamInitializerWithAnyOutput
1412
1450
) {
1413
1451
self . init (
@@ -1424,7 +1462,8 @@ extension NIOHTTP2Handler {
1424
1462
maximumResetFrameCount: streamConfiguration. streamResetFrameRateLimit. maximumCount,
1425
1463
resetFrameCounterWindow: streamConfiguration. streamResetFrameRateLimit. windowLength,
1426
1464
maximumStreamErrorCount: streamConfiguration. streamErrorRateLimit. maximumCount,
1427
- streamErrorCounterWindow: streamConfiguration. streamErrorRateLimit. windowLength
1465
+ streamErrorCounterWindow: streamConfiguration. streamErrorRateLimit. windowLength,
1466
+ frameDelegate: frameDelegate
1428
1467
)
1429
1468
self . inboundStreamMultiplexerState = . uninitializedAsync(
1430
1469
streamConfiguration,
0 commit comments