Socket
Socket
Sign inDemoInstall

@tinyhttp/forwarded

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinyhttp/forwarded - npm Package Compare versions

Comparing version 2.0.4 to 2.0.5

66

dist/index.js

@@ -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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc