Added DELETE and OPTIONS as supported web relay methods, #4241

Ylian Saint-Hilaire committed Jul 10, 2022 at 10:50 UTC 1a72126c4f5545a127675bf65c11777b743c453d
1 file changed +11 -1
webserver.js
+11 -1
@@ -5877,7 +5877,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
5877
5878 // If this is a web relay connection, handle it here.
5879 if ((obj.webRelayRouter != null) && (obj.args.relaydns.indexOf(req.hostname) >= 0)) {
5880 - if (['GET', 'POST', 'PUT', 'HEAD'].indexOf(req.method) >= 0) { return obj.webRelayRouter(req, res); } else { res.sendStatus(404); return; }
5880 + if (['GET', 'POST', 'PUT', 'HEAD', 'DELETE', 'OPTIONS'].indexOf(req.method) >= 0) { return obj.webRelayRouter(req, res); } else { res.sendStatus(404); return; }
5881 }
5882
5883 // Get the domain for this request
@@ -6613,6 +6613,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6613 const appid = parseInt(req.query.appid);
6614
6615 // Check to see if we already have a multi-relay session that matches exactly this device and port for this user
6616 + // TODO: Check that we have an exact session on any of the relay DNS names
6617 const xrelaySessionId = req.session.userid + '/' + req.session.x + '/' + req.hostname;
6618 const xrelaySession = webRelaySessions[xrelaySessionId];
6619 if ((xrelaySession != null) && (xrelaySession.domain.id == domain.id) && (xrelaySession.userid == userid) && (xrelaySession.nodeid == nodeid) && (xrelaySession.addr == addr) && (xrelaySession.port == port) && (xrelaySession.appid == appid)) {
@@ -6621,7 +6622,10 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6622 return;
6623 }
6624
6625 + // TODO: Check if there is a free relay DNS name we can use
6626 +
6627 // There is a relay session, but it's not correct, close it.
6628 + // TODO: Do this on the session that got the olders request
6629 if (xrelaySession != null) {
6630 xrelaySession.close();
6631 delete webRelaySessions[xrelaySessionId];
@@ -6655,6 +6659,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6659 // Handle all incoming requests as web relays
6660 obj.webRelayRouter.put('/*', function (req, res) { try { handleWebRelayRequest(req, res); } catch (ex) { console.log(ex); } })
6661
6662 + // Handle all incoming requests as web relays
6663 + obj.webRelayRouter.delete('/*', function (req, res) { try { handleWebRelayRequest(req, res); } catch (ex) { console.log(ex); } })
6664 +
6665 + // Handle all incoming requests as web relays
6666 + obj.webRelayRouter.options('/*', function (req, res) { try { handleWebRelayRequest(req, res); } catch (ex) { console.log(ex); } })
6667 +
6668 // Handle all incoming requests as web relays
6669 obj.webRelayRouter.head('/*', function (req, res) { try { handleWebRelayRequest(req, res); } catch (ex) { console.log(ex); } })
6670 }