From d1e0cd94e254609c6a34d269d9de6645e1a757bc Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 27 Jun 2022 13:48:13 -0700 Subject: [PATCH] Web relay can now stream chunk encoding towards relay device, #4172 --- apprelays.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apprelays.js b/apprelays.js index 46e7653b..aa1ca562 100644 --- a/apprelays.js +++ b/apprelays.js @@ -198,16 +198,16 @@ module.exports.CreateWebRelay = function (parent, db, args, domain) { request += '\r\n'; if (req.headers['content-length'] != null) { - // Stream the HTTP request and body, this is a content-length HTTP request, just forward the body dataf + // Stream the HTTP request and body, this is a content-length HTTP request, just forward the body data send(Buffer.from(request)); req.on('data', function (data) { send(data); }); // TODO: Flow control (Not sure how to do this in ExpressJS) req.on('end', function () { }); } else if (req.headers['transfer-encoding'] != null) { - // Read the HTTP body and send the request to the device - console.log('chunk stream start'); - obj.requestBinary = [Buffer.from(request)]; - req.on('data', function (data) { console.log('chunk stream data'); obj.requestBinary.push(data); }); - req.on('end', function () { console.log('chunk stream end');send(Buffer.concat(obj.requestBinary)); delete obj.requestBinary; }); + // Stream the HTTP request and body, this is a chunked encoded HTTP request + // TODO: Flow control (Not sure how to do this in ExpressJS) + send(Buffer.from(request)); + req.on('data', function (data) { send(Buffer.concat([Buffer.from(data.length.toString(16) + '\r\n', 'binary'), data, send(Buffer.from('\r\n', 'binary'))])); }); + req.on('end', function () { send(Buffer.from('0\r\n\r\n', 'binary')); }); } else { // Request has no body, send it now send(Buffer.from(request));