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

This commit is contained in:
Ylian Saint-Hilaire 2022-07-10 10:50:57 -07:00
parent a0ea6ead09
commit 1a72126c4f

View File

@ -5877,7 +5877,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
// If this is a web relay connection, handle it here. // If this is a web relay connection, handle it here.
if ((obj.webRelayRouter != null) && (obj.args.relaydns.indexOf(req.hostname) >= 0)) { 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 // 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); 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 // 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 xrelaySessionId = req.session.userid + '/' + req.session.x + '/' + req.hostname;
const xrelaySession = webRelaySessions[xrelaySessionId]; 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)) { 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; 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. // 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) { if (xrelaySession != null) {
xrelaySession.close(); xrelaySession.close();
delete webRelaySessions[xrelaySessionId]; delete webRelaySessions[xrelaySessionId];
@ -6655,6 +6659,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
// Handle all incoming requests as web relays // Handle all incoming requests as web relays
obj.webRelayRouter.put('/*', function (req, res) { try { handleWebRelayRequest(req, res); } catch (ex) { console.log(ex); } }) 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 // Handle all incoming requests as web relays
obj.webRelayRouter.head('/*', function (req, res) { try { handleWebRelayRequest(req, res); } catch (ex) { console.log(ex); } }) obj.webRelayRouter.head('/*', function (req, res) { try { handleWebRelayRequest(req, res); } catch (ex) { console.log(ex); } })
} }