Ensure preamble only gets sent once. (#61)

Motivation:

In certain cases it was possible for preamble to be sent once; this
would lead to frames getting sent more than once which in turn would
break state machines.

Modifications:

- Check the state of the connection before sending preamble.
- Include a test to check.

Result:

More correct implementation
This commit is contained in:
George Barnett authored and Cory Benfield committed 2019-03-15 12:40:50 +00:00
1 parent ddf2c29493
commit 348a10ee19
4 files changed
+48

No files matched your search

@@ -318,6 +318,10 @@ extension NIOHTTP2Handler {
extension NIOHTTP2Handler {
/// Issues the preamble when necessary.
private func writeAndFlushPreamble(context: ChannelHandlerContext) {
guard self.stateMachine.mustSendPreamble else {
return
}
if case .client = self.mode {
self.writeBuffer.clear()
self.writeBuffer.writeStaticString(NIOHTTP2Handler.clientMagic)