Web relay can now stream chunk encoding towards relay device, #4172
Ylian Saint-Hilaire committed
Jun 27, 2022 at 13:48 UTC
d1e0cd94e254609c6a34d269d9de6645e1a757bc
1 file changed
+6
-6
apprelays.js
+6
-6
@@ -198,16 +198,16 @@ module.exports.CreateWebRelay = function (parent, db, args, domain) {
198
request += '\r\n';
199
200
if (req.headers['content-length'] != null) {
201
- // Stream the HTTP request and body, this is a content-length HTTP request, just forward the body dataf
201
+ // Stream the HTTP request and body, this is a content-length HTTP request, just forward the body data
202
send(Buffer.from(request));
203
req.on('data', function (data) { send(data); }); // TODO: Flow control (Not sure how to do this in ExpressJS)
204
req.on('end', function () { });
205
} else if (req.headers['transfer-encoding'] != null) {
206
- // Read the HTTP body and send the request to the device
207
- console.log('chunk stream start');
208
- obj.requestBinary = [Buffer.from(request)];
209
- req.on('data', function (data) { console.log('chunk stream data'); obj.requestBinary.push(data); });
210
- req.on('end', function () { console.log('chunk stream end');send(Buffer.concat(obj.requestBinary)); delete obj.requestBinary; });
206
+ // Stream the HTTP request and body, this is a chunked encoded HTTP request
207
+ // TODO: Flow control (Not sure how to do this in ExpressJS)
208
+ send(Buffer.from(request));
209
+ req.on('data', function (data) { send(Buffer.concat([Buffer.from(data.length.toString(16) + '\r\n', 'binary'), data, send(Buffer.from('\r\n', 'binary'))])); });
210
+ req.on('end', function () { send(Buffer.from('0\r\n\r\n', 'binary')); });
211
} else {
212
// Request has no body, send it now
213
send(Buffer.from(request));