From ba87b529ddb2ccc8bc308fec83941b9e823f7820 Mon Sep 17 00:00:00 2001 From: Nicholas Hurley Date: Tue, 6 Sep 2016 14:18:10 -0700 Subject: [PATCH] Fix splitting for large frames. Fixes #207 I'm honestly not sure why this EVER worked - we were never limiting DATA frames to anything less than the flow control window. This fixes that to take into account the (default) max allowed payload size. Tested and works fine for me with node 6.4.0 --- example/server.js | 11 +++++++++++ lib/protocol/flow.js | 7 ++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/example/server.js b/example/server.js index 455e259..66d8f89 100644 --- a/example/server.js +++ b/example/server.js @@ -30,6 +30,17 @@ function onRequest(request, response) { fileStream.on('finish',response.end); } + // Example for testing large (boundary-sized) frames. + else if (request.url === "/largeframe") { + response.writeHead(200); + var body = 'a'; + for (var i = 0; i < 14; i++) { + body += body; + } + body = body + 'a'; + response.end(body); + } + // Otherwise responding with 404. else { response.writeHead(404); diff --git a/lib/protocol/flow.js b/lib/protocol/flow.js index 1647807..75562f0 100644 --- a/lib/protocol/flow.js +++ b/lib/protocol/flow.js @@ -249,8 +249,9 @@ Flow.prototype._parentPush = function _parentPush(frame) { // did not push the whole frame to the output queue (but maybe it did push part of the frame). Flow.prototype._push = function _push(frame) { var data = frame && (frame.type === 'DATA') && frame.data; + var maxFrameLength = (this._window < 16384) ? this._window : 16384; - if (!data || (data.length <= this._window)) { + if (!data || (data.length <= maxFrameLength)) { return this._parentPush(frame); } @@ -261,12 +262,12 @@ Flow.prototype._push = function _push(frame) { else { this._log.trace({ frame: frame, size: frame.data.length, forwardable: this._window }, 'Splitting out forwardable part of a DATA frame.'); - frame.data = data.slice(this._window); + frame.data = data.slice(maxFrameLength); this._parentPush({ type: 'DATA', flags: {}, stream: frame.stream, - data: data.slice(0, this._window) + data: data.slice(0, maxFrameLength) }); return null; }