@tinyhttp/forwarded
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -1,43 +0,35 @@ | ||
/** | ||
* Get all addresses in the request, using the `X-Forwarded-For` header. | ||
*/ | ||
function forwarded(req) { | ||
// simple header parsing | ||
const proxyAddrs = parse(req.headers['x-forwarded-for'] || ''); | ||
const socketAddr = req.connection.remoteAddress; | ||
// return all addresses | ||
return [socketAddr].concat(proxyAddrs); | ||
const proxyAddrs = parse(req.headers["x-forwarded-for"] || ""); | ||
const socketAddr = req.connection.remoteAddress; | ||
return [socketAddr].concat(proxyAddrs); | ||
} | ||
/** | ||
* Parse the X-Forwarded-For header. | ||
*/ | ||
function parse(header) { | ||
let end = header.length; | ||
const list = []; | ||
let start = header.length; | ||
// gather addresses, backwards | ||
for (let i = header.length - 1; i >= 0; i--) { | ||
switch (header.charCodeAt(i)) { | ||
case 0x20 /* */: | ||
if (start === end) { | ||
start = end = i; | ||
} | ||
break; | ||
case 0x2c /* , */: | ||
if (start !== end) { | ||
list.push(header.substring(start, end)); | ||
} | ||
start = end = i; | ||
break; | ||
default: | ||
start = i; | ||
break; | ||
let end = header.length; | ||
const list = []; | ||
let start = header.length; | ||
for (let i = header.length - 1; i >= 0; i--) { | ||
switch (header.charCodeAt(i)) { | ||
case 32: | ||
if (start === end) { | ||
start = end = i; | ||
} | ||
break; | ||
case 44: | ||
if (start !== end) { | ||
list.push(header.substring(start, end)); | ||
} | ||
start = end = i; | ||
break; | ||
default: | ||
start = i; | ||
break; | ||
} | ||
// final address | ||
if (start !== end) | ||
list.push(header.substring(start, end)); | ||
return list; | ||
} | ||
if (start !== end) | ||
list.push(header.substring(start, end)); | ||
return list; | ||
} | ||
export { forwarded, parse }; | ||
export { | ||
forwarded, | ||
parse | ||
}; |
{ | ||
"name": "@tinyhttp/forwarded", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"type": "module", | ||
@@ -34,4 +34,6 @@ "description": "forwarded rewrite with TypeScript and ESM support", | ||
"scripts": { | ||
"build": "rollup -c ../../build/defaultConfig.js" | ||
"dev": "vite", | ||
"build": "vite build", | ||
"postbuild": "tsc --emitDeclarationOnly" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3243
45