[dart:io] Fix WebSocket deflate compression of empty fragments.

It currently compresses the empty fragment to zero bytes. However, RFC 7692
"Compression Extensions for WebSocket" 6.2.3.6. "Generating an Empty
Fragment" says that if the compression library produces no data, then an
empty uncompressed deflate block is used for this purpose. The 0x00 block
has the BFINAL header bit set to 0 and the BTYPE header set to 00 along with
5 bits of padding. This block decodes to zero bytes.

Chrome aborts the "Invalid frame header" when it receives a compressed
websocket frame with a zero length payload. This change fixes the websocket
implementation so it sends the 0x00 byte instead which decodes to the empty
data.

Bug: https://github.com/dart-lang/sdk/issues/35540
Change-Id: I581bf2cd362a25c5d88c9d9e31e8499a99f5fd13
Reviewed-on: https://dart-review.googlesource.com/c/88187
Reviewed-by: William Hesse <whesse@google.com>
Commit-Queue: Jonas Termansen <sortie@google.com>
This commit is contained in:
Jonas Termansen 2019-01-03 12:52:46 +00:00 committed by commit-bot@chromium.org
parent ff10e5dd22
commit 822ec43ab5

View file

@ -649,6 +649,15 @@ class _WebSocketPerMessageDeflate {
result = result.sublist(0, result.length - 4);
}
// RFC 7692 7.2.3.6. "Generating an Empty Fragment" says that if the
// compression library doesn't generate any data when the bufer is empty,
// then an empty uncompressed deflate block is used for this purpose. The
// 0x00 block has the BFINAL header bit set to 0 and the BTYPE header set to
// 00 along with 5 bits of padding. This block decodes to zero bytes.
if (result.length == 0) {
return [0x00];
}
return result;
}
}