Skip to content

Commit

Permalink
Adjusted logic for parsing request.
Browse files Browse the repository at this point in the history
  • Loading branch information
shinylightdev committed Jan 27, 2021
1 parent bb1271a commit 55b1424
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
"scripts": {
"test": "jest",
"start": "node app.js",
"publish": "node ./scripts/publish.js"
"publish": "node ./scripts/publish.js"
},
"author": "ShinyLight",
"license": "ISC",
"dependencies": {
"copy-dir": "^1.3.0",
"http-string-parser": "^0.0.6",
"jest": "^26.6.3",
"moment": "^2.29.1",
"sqlite3": "^5.0.0",
"sqlite3-helper": "^2.0.1"
}
}
}
}
27 changes: 21 additions & 6 deletions proxy/proxy.handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ exports.BlockRequest = BlockRequest;
exports.AllowSecureRequest = AllowSecureRequest;
exports.AllowUnsecureRequest = AllowUnsecureRequest;
exports.RunForEachConnection = RunForEachConnection;
exports.IsNormalInteger = IsNormalInteger;



/**
* Checks to see if it's a positive integer.
*
* @param {*} str
* @returns
*/
function IsNormalInteger(str) {
return /^\+?(0|[1-9]\d*)$/.test(str);
}



/**
* Parses buffer data into Json object.
Expand All @@ -36,12 +51,12 @@ function GetDetailsFromBuffer(buffer, isOnWhiteList) {
// ALWAYS INCLUDE INDEX 0
// ON INDEX 1 and above, loop through all lines until you
// only have User-Agent and Host
const isHttps = Utils.GetToken(bufferLines[0], " ", 0) === "CONNECT";
const domain = Utils.GetToken(bufferLines[1], ":", 1).trim();
const port = Utils.GetToken(bufferLines[1], ":", 2).trim() || defaultPort;
const userAgent = Utils.GetToken(bufferLines[3], ":", 1).trim();
const domainRoot = Utils.GetDomainRoot(domain);

const isHttps = request.method == "CONNECT" && request.uri.endsWith(":443");
const port = isHttps ? "443" : ( IsNormalInteger(GetToken(request.uri, ":", 1)) ? GetToken(request.uri, ":", 1) : defaultPort) || "";
const domain = (request.headers['Host'] || "").replace(":" + port, "");
const userAgent = request.headers['User-Agent'] || "";
const domainRoot = Utils.GetDomainRoot(domain);

return {
isHttps: isHttps ? 1 : 0,
Expand Down

0 comments on commit 55b1424

Please sign in to comment.