From 1a72126c4f5545a127675bf65c11777b743c453d Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Sun, 10 Jul 2022 10:50:57 -0700 Subject: [PATCH] Added DELETE and OPTIONS as supported web relay methods, #4241 --- webserver.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/webserver.js b/webserver.js index cfc2d338..65ed56fc 100644 --- a/webserver.js +++ b/webserver.js @@ -5877,7 +5877,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF // If this is a web relay connection, handle it here. if ((obj.webRelayRouter != null) && (obj.args.relaydns.indexOf(req.hostname) >= 0)) { - if (['GET', 'POST', 'PUT', 'HEAD'].indexOf(req.method) >= 0) { return obj.webRelayRouter(req, res); } else { res.sendStatus(404); return; } + if (['GET', 'POST', 'PUT', 'HEAD', 'DELETE', 'OPTIONS'].indexOf(req.method) >= 0) { return obj.webRelayRouter(req, res); } else { res.sendStatus(404); return; } } // Get the domain for this request @@ -6613,6 +6613,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF const appid = parseInt(req.query.appid); // Check to see if we already have a multi-relay session that matches exactly this device and port for this user + // TODO: Check that we have an exact session on any of the relay DNS names const xrelaySessionId = req.session.userid + '/' + req.session.x + '/' + req.hostname; const xrelaySession = webRelaySessions[xrelaySessionId]; 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 return; } + // TODO: Check if there is a free relay DNS name we can use + // There is a relay session, but it's not correct, close it. + // TODO: Do this on the session that got the olders request if (xrelaySession != null) { xrelaySession.close(); delete webRelaySessions[xrelaySessionId]; @@ -6655,6 +6659,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF // Handle all incoming requests as web relays obj.webRelayRouter.put('/*', function (req, res) { try { handleWebRelayRequest(req, res); } catch (ex) { console.log(ex); } }) + // Handle all incoming requests as web relays + obj.webRelayRouter.delete('/*', function (req, res) { try { handleWebRelayRequest(req, res); } catch (ex) { console.log(ex); } }) + + // Handle all incoming requests as web relays + obj.webRelayRouter.options('/*', function (req, res) { try { handleWebRelayRequest(req, res); } catch (ex) { console.log(ex); } }) + // Handle all incoming requests as web relays obj.webRelayRouter.head('/*', function (req, res) { try { handleWebRelayRequest(req, res); } catch (ex) { console.log(ex); } }) }