From a62839e881ed9bb49b484d910986ba127ef45bdd Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 7 Mar 2017 10:48:20 -0800 Subject: [PATCH] Fix GOAWAY deserialization when debug data is present Additional debug data is allowed to be included in the GOAWAY frame: https://http2.github.io/http2-spec/#GOAWAY. We now put that data into frame.debug_data instead of returning a FRAME_SIZE_ERROR. Fixes #218 and #219. --- lib/protocol/framer.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/protocol/framer.js b/lib/protocol/framer.js index 244e60a..4e273df 100644 --- a/lib/protocol/framer.js +++ b/lib/protocol/framer.js @@ -736,6 +736,8 @@ typeSpecificAttributes.GOAWAY = ['last_stream', 'error']; // +-+-------------------------------------------------------------+ // | Error Code (32) | // +---------------------------------------------------------------+ +// | Additional Debug Data (*) | +// +---------------------------------------------------------------+ // // The last stream identifier in the GOAWAY frame contains the highest numbered stream identifier // for which the sender of the GOAWAY frame has received frames on and might have taken some action @@ -759,8 +761,8 @@ Serializer.GOAWAY = function writeGoaway(frame, buffers) { }; Deserializer.GOAWAY = function readGoaway(buffer, frame) { - if (buffer.length !== 8) { - // GOAWAY must have 8 bytes + if (buffer.length < 8) { + // GOAWAY must have at least 8 bytes return 'FRAME_SIZE_ERROR'; } frame.last_stream = buffer.readUInt32BE(0) & 0x7fffffff; @@ -769,6 +771,12 @@ Deserializer.GOAWAY = function readGoaway(buffer, frame) { // Unknown error types are to be considered equivalent to INTERNAL ERROR frame.error = 'INTERNAL_ERROR'; } + // Read remaining data into "debug_data" + // https://http2.github.io/http2-spec/#GOAWAY + // Endpoints MAY append opaque data to the payload of any GOAWAY frame + if (buffer.length > 8) { + frame.debug_data = buffer.slice(8); + } }; // [WINDOW_UPDATE](https://tools.ietf.org/html/rfc7540#section-6.9)