From e8014f4048ac9362349f56175c13c53e64413b73 Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Tue, 22 Nov 2016 13:31:58 +1100 Subject: [PATCH 1/3] Added support for binary Allows encoding to be set to binary and pass in buffer rather than string. Solves a problem when returning binary files via fastcgi backend. --- lib/fastcgi.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/fastcgi.js b/lib/fastcgi.js index 090a37f..d8f9a34 100644 --- a/lib/fastcgi.js +++ b/lib/fastcgi.js @@ -342,6 +342,9 @@ function Writer() { case "utf8": _pos += _buffer.utf8Write(body, _pos, _buffer.length - _pos); break; + case "binary": + _record.body = _body.slice(0, _record.header.contentLength); + break; default: body.copy(_buffer, _pos); _pos += body.length; From 713df52515252c808e2f88a983d4033ab0c72dfa Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Tue, 22 Nov 2016 13:38:14 +1100 Subject: [PATCH 2/3] Attempt 2 at applying the fix for binary buffers --- lib/fastcgi.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/fastcgi.js b/lib/fastcgi.js index 090a37f..be6523f 100644 --- a/lib/fastcgi.js +++ b/lib/fastcgi.js @@ -227,6 +227,9 @@ function Parser() { case "ascii": _record.body = _body.asciiSlice(0, _record.header.contentLength); break; + case "binary": + _record.body = _body.slice(0, _record.header.contentLength); + break; default: _parser.onBody(_body, 0, _record.header.contentLength); break; From e88eb41480d7ba892b454b4381e604ebe6adfec7 Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Tue, 22 Nov 2016 13:40:46 +1100 Subject: [PATCH 3/3] Move patch to correct spot. --- lib/fastcgi.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fastcgi.js b/lib/fastcgi.js index d8f9a34..be6523f 100644 --- a/lib/fastcgi.js +++ b/lib/fastcgi.js @@ -227,6 +227,9 @@ function Parser() { case "ascii": _record.body = _body.asciiSlice(0, _record.header.contentLength); break; + case "binary": + _record.body = _body.slice(0, _record.header.contentLength); + break; default: _parser.onBody(_body, 0, _record.header.contentLength); break; @@ -342,9 +345,6 @@ function Writer() { case "utf8": _pos += _buffer.utf8Write(body, _pos, _buffer.length - _pos); break; - case "binary": - _record.body = _body.slice(0, _record.header.contentLength); - break; default: body.copy(_buffer, _pos); _pos += body.length;