mirror of
https://github.com/apple/swift-nio-http2
synced 2026-11-30 05:28:45 +00:00
Respect target window size on inbound channels. (#205)
Motivation: As part of #202 we added support for configuring the target window size of stream channels. That was plumbed through into outbound channels, but we missed the inbound ones, meaning that this only really worked for clients, not servers. That hardly seems fair! Modifications: Pass target window size to inbound channels too. Result: We can control target window size of inbound channels.
This commit is contained in:
1 parent
5b31110289
commit
c8f952dbc3
3 files changed
+36
-1
No files matched your search
@@ -79,7 +79,7 @@ public final class HTTP2StreamMultiplexer: ChannelInboundHandler, ChannelOutboun
|
||||
parent: self.channel,
|
||||
multiplexer: self,
|
||||
streamID: streamID,
|
||||
targetWindowSize: 65535,
|
||||
targetWindowSize: Int32(self.targetWindowSize),
|
||||
outboundBytesHighWatermark: self.streamChannelOutboundBytesHighWatermark,
|
||||
outboundBytesLowWatermark: self.streamChannelOutboundBytesLowWatermark)
|
||||
self.streams[streamID] = channel
|
||||
|
||||
@@ -71,6 +71,7 @@ extension HTTP2StreamMultiplexerTests {
|
||||
("testMultiplexerModifiesStreamChannelWritabilityBasedOnParentChannelWritability", testMultiplexerModifiesStreamChannelWritabilityBasedOnParentChannelWritability),
|
||||
("testMultiplexerModifiesStreamChannelWritabilityBasedOnFixedSizeTokensAndChannelWritability", testMultiplexerModifiesStreamChannelWritabilityBasedOnFixedSizeTokensAndChannelWritability),
|
||||
("testStreamChannelToleratesFailingInitialier", testStreamChannelToleratesFailingInitialier),
|
||||
("testInboundChannelWindowSizeIsCustomisable", testInboundChannelWindowSizeIsCustomisable),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1794,4 +1794,38 @@ final class HTTP2StreamMultiplexerTests: XCTestCase {
|
||||
self.channel.embeddedEventLoop.run()
|
||||
}
|
||||
|
||||
func testInboundChannelWindowSizeIsCustomisable() throws {
|
||||
let targetWindowSize = 1 << 18
|
||||
|
||||
let multiplexer = HTTP2StreamMultiplexer(mode: .client,
|
||||
channel: self.channel,
|
||||
targetWindowSize: targetWindowSize) { (channel, streamID) in
|
||||
return channel.eventLoop.makeSucceededFuture(())
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try self.channel.pipeline.addHandler(multiplexer).wait())
|
||||
XCTAssertNoThrow(try self.channel.connect(to: SocketAddress(ipAddress: "1.2.3.4", port: 5)).wait())
|
||||
|
||||
// Ok, create an inbound channel.
|
||||
let frame = HTTP2Frame(streamID: HTTP2StreamID(1), payload: .headers(.init(headers: HPACKHeaders())))
|
||||
XCTAssertNoThrow(try self.channel.writeInbound(frame))
|
||||
|
||||
// Now claim that the window got consumed. Nothing happens.
|
||||
XCTAssertNoThrow(try XCTAssertNil(self.channel.readOutbound(as: HTTP2Frame.self)))
|
||||
var windowEvent = NIOHTTP2WindowUpdatedEvent(streamID: 1, inboundWindowSize: (targetWindowSize / 2) + 1, outboundWindowSize: nil)
|
||||
channel.pipeline.fireUserInboundEventTriggered(windowEvent)
|
||||
XCTAssertNoThrow(try XCTAssertNil(self.channel.readOutbound(as: HTTP2Frame.self)))
|
||||
|
||||
// Consume the last byte.
|
||||
windowEvent = NIOHTTP2WindowUpdatedEvent(streamID: 1, inboundWindowSize: (targetWindowSize / 2), outboundWindowSize: nil)
|
||||
channel.pipeline.fireUserInboundEventTriggered(windowEvent)
|
||||
guard let receivedFrame = try assertNoThrowWithValue(self.channel.readOutbound(as: HTTP2Frame.self)) else {
|
||||
XCTFail("No frame received")
|
||||
return
|
||||
}
|
||||
|
||||
receivedFrame.assertWindowUpdateFrame(streamID: 1, windowIncrement: targetWindowSize / 2)
|
||||
XCTAssertNoThrow(try channel.finish(acceptAlreadyClosed: false))
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user