diff --git a/src/handlers/proxyHandler.js b/src/handlers/proxyHandler.js index 7027e51..7dc2c55 100644 --- a/src/handlers/proxyHandler.js +++ b/src/handlers/proxyHandler.js @@ -1,3 +1,5 @@ +const generateServerString = require("../utils/generateServerString"); + let serverconsole = {}; let middleware = []; @@ -34,9 +36,26 @@ function proxyHandler(req, socket, head) { var reqip = socket.remoteAddress; var reqport = socket.remotePort; process.reqcounter++; - logFacilities.locmessage("Somebody connected to " + (config.secure ? ((typeof config.sport == "number" ? "port " : "socket ") + sport) : ((typeof config.port == "number" ? "port " : "socket ") + config.port)) + "..."); - logFacilities.reqmessage("Client " + ((!reqip || reqip == "") ? "[unknown client]" : (reqip + ((reqport && reqport !== 0) && reqport != "" ? ":" + reqport : ""))) + " wants to proxy " + req.url + " through this server"); - if (req.headers["user-agent"] != undefined) logFacilities.reqmessage("Client uses " + req.headers["user-agent"]); + logFacilities.locmessage( + "Somebody connected to " + + (config.secure + ? (typeof config.sport == "number" ? "port " : "socket ") + config.sport + : (typeof config.port == "number" ? "port " : "socket ") + + config.port) + + "...", + ); + logFacilities.reqmessage( + "Client " + + (!reqip || reqip == "" + ? "[unknown client]" + : reqip + + (reqport && reqport !== 0 && reqport != "" ? ":" + reqport : "")) + + " wants to proxy " + + req.url + + " through this server", + ); + if (req.headers["user-agent"] != undefined) + logFacilities.reqmessage("Client uses " + req.headers["user-agent"]); let index = 0; @@ -55,10 +74,13 @@ function proxyHandler(req, socket, head) { ); logFacilities.errmessage("Stack:"); logFacilities.errmessage(err.stack); - if (!socket.destroyed) socket.end("HTTP/1.1 500 Internal Server Error\n\n"); + if (!socket.destroyed) + socket.end("HTTP/1.1 500 Internal Server Error\n\n"); } } else { - logFacilities.errmessage("SVR.JS doesn't support proxy without proxy mod."); + logFacilities.errmessage( + "SVR.JS doesn't support proxy without proxy mod.", + ); if (!socket.destroyed) socket.end("HTTP/1.1 501 Not Implemented\n\n"); } }; @@ -72,4 +94,3 @@ module.exports = (serverconsoleO, middlewareO) => { middleware = middlewareO; return proxyHandler; }; - \ No newline at end of file diff --git a/src/handlers/requestHandler.js b/src/handlers/requestHandler.js index c39f6e8..5550dde 100644 --- a/src/handlers/requestHandler.js +++ b/src/handlers/requestHandler.js @@ -710,7 +710,12 @@ function requestHandler(req, res) { // Call the next middleware function const next = () => { let currentMiddleware = middleware[index++]; - while (req.isProxy && currentMiddleware && currentMiddleware.proxySafe !== false && !(currentMiddleware.proxySafe || currentMiddleware.proxy)) { + while ( + req.isProxy && + currentMiddleware && + currentMiddleware.proxySafe !== false && + !(currentMiddleware.proxySafe || currentMiddleware.proxy) + ) { currentMiddleware = middleware[index++]; } if (currentMiddleware) { diff --git a/src/middleware/checkForbiddenPaths.js b/src/middleware/checkForbiddenPaths.js index ed50dec..dd3f711 100644 --- a/src/middleware/checkForbiddenPaths.js +++ b/src/middleware/checkForbiddenPaths.js @@ -112,4 +112,4 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; -module.exports.proxySafe = true; \ No newline at end of file +module.exports.proxySafe = true; diff --git a/src/middleware/defaultHandlerChecks.js b/src/middleware/defaultHandlerChecks.js index 5958cb5..e2cc433 100644 --- a/src/middleware/defaultHandlerChecks.js +++ b/src/middleware/defaultHandlerChecks.js @@ -38,4 +38,4 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; -module.exports.proxySafe = true; \ No newline at end of file +module.exports.proxySafe = true; diff --git a/src/middleware/nonStandardCodesAndHttpAuthentication.js b/src/middleware/nonStandardCodesAndHttpAuthentication.js index 9f8f8ad..07ebbdb 100644 --- a/src/middleware/nonStandardCodesAndHttpAuthentication.js +++ b/src/middleware/nonStandardCodesAndHttpAuthentication.js @@ -463,4 +463,4 @@ module.exports.commands = { }, }; -module.exports.proxySafe = true; \ No newline at end of file +module.exports.proxySafe = true; diff --git a/src/middleware/redirectTrailingSlashes.js b/src/middleware/redirectTrailingSlashes.js index c20dc61..171771b 100644 --- a/src/middleware/redirectTrailingSlashes.js +++ b/src/middleware/redirectTrailingSlashes.js @@ -33,4 +33,4 @@ module.exports = (req, res, logFacilities, config, next) => { } }; -module.exports.proxySafe = true; \ No newline at end of file +module.exports.proxySafe = true; diff --git a/src/middleware/redirects.js b/src/middleware/redirects.js index 14d8ca2..78b6744 100644 --- a/src/middleware/redirects.js +++ b/src/middleware/redirects.js @@ -80,4 +80,4 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; -module.exports.proxySafe = true; \ No newline at end of file +module.exports.proxySafe = true; diff --git a/src/middleware/responseHeaders.js b/src/middleware/responseHeaders.js index 3b89fc7..e341e21 100644 --- a/src/middleware/responseHeaders.js +++ b/src/middleware/responseHeaders.js @@ -13,4 +13,4 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; -module.exports.proxySafe = true; \ No newline at end of file +module.exports.proxySafe = true; diff --git a/src/middleware/rewriteURL.js b/src/middleware/rewriteURL.js index 96c0817..baf6e8c 100644 --- a/src/middleware/rewriteURL.js +++ b/src/middleware/rewriteURL.js @@ -154,4 +154,4 @@ module.exports = (req, res, logFacilities, config, next) => { }); }; -module.exports.proxySafe = true; \ No newline at end of file +module.exports.proxySafe = true; diff --git a/src/middleware/staticFileServingAndDirectoryListings.js b/src/middleware/staticFileServingAndDirectoryListings.js index d184360..d0a48e7 100644 --- a/src/middleware/staticFileServingAndDirectoryListings.js +++ b/src/middleware/staticFileServingAndDirectoryListings.js @@ -991,4 +991,4 @@ module.exports = (req, res, logFacilities, config, next) => { }); }; -module.exports.proxySafe = true; \ No newline at end of file +module.exports.proxySafe = true; diff --git a/src/middleware/status.js b/src/middleware/status.js index f36bba8..06b6115 100644 --- a/src/middleware/status.js +++ b/src/middleware/status.js @@ -135,4 +135,4 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; -module.exports.proxySafe = true; \ No newline at end of file +module.exports.proxySafe = true; diff --git a/src/middleware/urlSanitizer.js b/src/middleware/urlSanitizer.js index 68dcab8..36e4282 100644 --- a/src/middleware/urlSanitizer.js +++ b/src/middleware/urlSanitizer.js @@ -53,4 +53,4 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; -module.exports.proxySafe = true; \ No newline at end of file +module.exports.proxySafe = true; diff --git a/src/middleware/webRootPostfixes.js b/src/middleware/webRootPostfixes.js index ee6dfdd..9883645 100644 --- a/src/middleware/webRootPostfixes.js +++ b/src/middleware/webRootPostfixes.js @@ -141,4 +141,4 @@ module.exports = (req, res, logFacilities, config, next) => { next(); }; -module.exports.proxySafe = true; \ No newline at end of file +module.exports.proxySafe = true;