Skip to content

Commit ba87b52

Browse files
committed
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
1 parent 8a0869b commit ba87b52

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

example/server.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ function onRequest(request, response) {
3030
fileStream.on('finish',response.end);
3131
}
3232

33+
// Example for testing large (boundary-sized) frames.
34+
else if (request.url === "/largeframe") {
35+
response.writeHead(200);
36+
var body = 'a';
37+
for (var i = 0; i < 14; i++) {
38+
body += body;
39+
}
40+
body = body + 'a';
41+
response.end(body);
42+
}
43+
3344
// Otherwise responding with 404.
3445
else {
3546
response.writeHead(404);

lib/protocol/flow.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ Flow.prototype._parentPush = function _parentPush(frame) {
249249
// did not push the whole frame to the output queue (but maybe it did push part of the frame).
250250
Flow.prototype._push = function _push(frame) {
251251
var data = frame && (frame.type === 'DATA') && frame.data;
252+
var maxFrameLength = (this._window < 16384) ? this._window : 16384;
252253

253-
if (!data || (data.length <= this._window)) {
254+
if (!data || (data.length <= maxFrameLength)) {
254255
return this._parentPush(frame);
255256
}
256257

@@ -261,12 +262,12 @@ Flow.prototype._push = function _push(frame) {
261262
else {
262263
this._log.trace({ frame: frame, size: frame.data.length, forwardable: this._window },
263264
'Splitting out forwardable part of a DATA frame.');
264-
frame.data = data.slice(this._window);
265+
frame.data = data.slice(maxFrameLength);
265266
this._parentPush({
266267
type: 'DATA',
267268
flags: {},
268269
stream: frame.stream,
269-
data: data.slice(0, this._window)
270+
data: data.slice(0, maxFrameLength)
270271
});
271272
return null;
272273
}

0 commit comments

Comments
 (0)