Added support for text/event-stream in web relay (#4369)
Ylian Saint-Hilaire committed
Aug 5, 2022 at 11:47 UTC
046dd30786e1560e9e9ae8cf69b61055d17ab301
1 file changed
+7
-3
apprelays.js
+7
-3
@@ -136,8 +136,8 @@ module.exports.CreateWebRelaySession = function (parent, db, req, args, domain,
136
// Check to see if any of the tunnels are free
137
var count = 0;
138
for (var i in tunnels) {
139
- count += (tunnels[i].isWebSocket ? 0 : 1);
140
- if ((tunnels[i].relayActive == true) && (tunnels[i].res == null) && (tunnels[i].isWebSocket == false)) {
139
+ count += ((tunnels[i].isWebSocket || tunnels[i].isStreaming) ? 0 : 1);
140
+ if ((tunnels[i].relayActive == true) && (tunnels[i].res == null) && (tunnels[i].isWebSocket == false) && (tunnels[i].isStreaming == false)) {
141
// Found a free tunnel, use it
142
const x = pendingRequests.shift();
143
if (x[2] == true) { tunnels[i].processWebSocket(x[0], x[1]); } else { tunnels[i].processRequest(x[0], x[1]); }
@@ -226,7 +226,8 @@ module.exports.CreateWebRelay = function (parent, db, args, domain) {
226
obj.lastOperation = Date.now();
227
obj.relayActive = false;
228
obj.closed = false;
229
- obj.isWebSocket = false;
229
+ obj.isWebSocket = false; // If true, this request will not close and so, it can't be allowed to hold up other requests
230
+ obj.isStreaming = false; // If true, this request will not close and so, it can't be allowed to hold up other requests
231
obj.processedRequestCount = 0;
232
const constants = (require('crypto').constants ? require('crypto').constants : require('constants')); // require('constants') is deprecated in Node 11.10, use require('crypto').constants instead.
233
@@ -243,6 +244,9 @@ module.exports.CreateWebRelay = function (parent, db, args, domain) {
244
// Check if this is a websocket
245
if (req.headers['upgrade'] == 'websocket') { console.log('Attempt to process a websocket in HTTP tunnel method.'); res.end(); return false; }
246
247
+ // Check if this is a streaming request
248
+ if ((req.headers['content-type'] != null) && (req.headers['content-type'].toLowerCase() == 'text/event-stream')) { obj.isStreaming = true; }
249
+
250
// Construct the HTTP request
251
var request = req.method + ' ' + req.url + ' HTTP/' + req.httpVersion + '\r\n';
252
const blockedHeaders = ['origin', 'cookie', 'upgrade-insecure-requests', 'sec-ch-ua', 'sec-ch-ua-mobile', 'dnt', 'sec-fetch-user', 'sec-ch-ua-platform', 'sec-fetch-site', 'sec-fetch-mode', 'sec-fetch-dest']; // These are headers we do not forward