Fixed server crashes with invalid HTTP/2 status codes
This commit is contained in:
parent
2a0560f5f2
commit
791c803d64
1 changed files with 21 additions and 17 deletions
38
index.js
38
index.js
|
@ -42,7 +42,7 @@ Mod.prototype.callback = function callback(req, res, serverconsole, responseEnd,
|
||||||
if (!port) port = 80;
|
if (!port) port = 80;
|
||||||
if (!securePort && secureHostname) securePort = 443;
|
if (!securePort && secureHostname) securePort = 443;
|
||||||
if (!hostname) {
|
if (!hostname) {
|
||||||
callServerError(500, "reverse-proxy-mod/1.1.1", new Error("Proxy server is misconfigured. Hostname property is missing."));
|
callServerError(500, "reverse-proxy-mod/1.1.2", new Error("Proxy server is misconfigured. Hostname property is missing."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -94,14 +94,14 @@ Mod.prototype.callback = function callback(req, res, serverconsole, responseEnd,
|
||||||
}).on("error", (ex) => {
|
}).on("error", (ex) => {
|
||||||
try {
|
try {
|
||||||
if (ex.code == "ENOTFOUND" || ex.code == "EHOSTUNREACH" || ex.code == "ECONNREFUSED") {
|
if (ex.code == "ENOTFOUND" || ex.code == "EHOSTUNREACH" || ex.code == "ECONNREFUSED") {
|
||||||
callServerError(503, "reverse-proxy-mod/1.1.1", ex); //Server error
|
callServerError(503, "reverse-proxy-mod/1.1.2", ex); //Server error
|
||||||
} else if (ex.code == "ETIMEDOUT") {
|
} else if (ex.code == "ETIMEDOUT") {
|
||||||
callServerError(504, "reverse-proxy-mod/1.1.1", ex); //Server error
|
callServerError(504, "reverse-proxy-mod/1.1.2", ex); //Server error
|
||||||
} else {
|
} else {
|
||||||
callServerError(502, "reverse-proxy-mod/1.1.1", ex); //Server error
|
callServerError(502, "reverse-proxy-mod/1.1.2", ex); //Server error
|
||||||
}
|
}
|
||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
serverconsole.errmessage("Client fails to recieve content."); //Log into SVR.JS
|
serverconsole.errmessage("Client fails to recieve content."); //Log into SVR.JS
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (String(hdrs["connection"]).toLowerCase() != "upgrade") hdrs["connection"] = "close";
|
if (String(hdrs["connection"]).toLowerCase() != "upgrade") hdrs["connection"] = "close";
|
||||||
|
@ -124,22 +124,26 @@ Mod.prototype.callback = function callback(req, res, serverconsole, responseEnd,
|
||||||
delete sres.headers["Transfer-Encoding"];
|
delete sres.headers["Transfer-Encoding"];
|
||||||
delete sres.headers["keep-alive"];
|
delete sres.headers["keep-alive"];
|
||||||
delete sres.headers["Keep-Alive"];
|
delete sres.headers["Keep-Alive"];
|
||||||
res.writeHead(sres.statusCode, sres.headers);
|
try {
|
||||||
sres.pipe(res);
|
res.writeHead(sres.statusCode, sres.headers);
|
||||||
res.prependListener("end", function () {
|
sres.pipe(res);
|
||||||
try {
|
res.prependListener("end", function () {
|
||||||
sres.end();
|
try {
|
||||||
} catch (ex) {}
|
sres.end();
|
||||||
});
|
} catch (ex) {}
|
||||||
|
});
|
||||||
|
} catch (ex) {
|
||||||
|
callServerError(502, "reverse-proxy-mod/1.1.2", ex); //Server error
|
||||||
|
}
|
||||||
});
|
});
|
||||||
proxy.on("error", (ex) => {
|
proxy.on("error", function (ex) {
|
||||||
try {
|
try {
|
||||||
if (ex.code == "ENOTFOUND" || ex.code == "EHOSTUNREACH" || ex.code == "ECONNREFUSED") {
|
if (ex.code == "ENOTFOUND" || ex.code == "EHOSTUNREACH" || ex.code == "ECONNREFUSED") {
|
||||||
callServerError(503, "reverse-proxy-mod/1.1.1", ex); //Server error
|
callServerError(503, "reverse-proxy-mod/1.1.2", ex); //Server error
|
||||||
} else if (ex.code == "ETIMEDOUT") {
|
} else if (ex.code == "ETIMEDOUT") {
|
||||||
callServerError(504, "reverse-proxy-mod/1.1.1", ex); //Server error
|
callServerError(504, "reverse-proxy-mod/1.1.2", ex); //Server error
|
||||||
} else {
|
} else {
|
||||||
callServerError(502, "reverse-proxy-mod/1.1.1", ex); //Server error
|
callServerError(502, "reverse-proxy-mod/1.1.2", ex); //Server error
|
||||||
}
|
}
|
||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
serverconsole.errmessage("Client fails to recieve content."); //Log into SVR.JS
|
serverconsole.errmessage("Client fails to recieve content."); //Log into SVR.JS
|
||||||
|
@ -152,7 +156,7 @@ Mod.prototype.callback = function callback(req, res, serverconsole, responseEnd,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if ((href == "/reverse-proxy-config.json" || (os.platform() == "win32" && href.toLowerCase() == "/reverse-proxy-config.json")) && path.normalize(__dirname + "/../../..") == process.cwd()) {
|
} else if ((href == "/reverse-proxy-config.json" || (os.platform() == "win32" && href.toLowerCase() == "/reverse-proxy-config.json")) && path.normalize(__dirname + "/../../..") == process.cwd()) {
|
||||||
callServerError(403, "reverse-proxy-mod/1.1.1");
|
callServerError(403, "reverse-proxy-mod/1.1.2");
|
||||||
} else {
|
} else {
|
||||||
elseCallback();
|
elseCallback();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue