@vandenberghinc/volt 1.2.20 → 1.2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -91,8 +91,6 @@ class Stream {
91
91
  if (this.http1) {
92
92
  this.headers = this.req.headers;
93
93
  }
94
- this._ip = this.http2 ? this.s.session.socket.remoteAddress : this.req.socket.remoteAddress;
95
- this._port = this.http2 ? this.s.session.socket.remotePort : this.req.socket.remotePort;
96
94
  this._method = this.http2 ? this.headers[":method"] : this.req.method;
97
95
  this._params = void 0;
98
96
  this._is_query_params = false;
@@ -104,6 +102,14 @@ class Stream {
104
102
  this.finished = false;
105
103
  this.res_cookies = [];
106
104
  this.res_headers = this.http1 ? [] : {};
105
+ const unpack_ip_header = (value) => {
106
+ if (value == null) {
107
+ return void 0;
108
+ }
109
+ return (Array.isArray(value) ? value[0] : value) || void 0;
110
+ };
111
+ this._ip = unpack_ip_header(this.headers["x-forwarded-for"]) || unpack_ip_header(this.headers["x-real-ip"]) || (this.http2 ? this.s.session?.socket?.remoteAddress : this.req?.socket?.remoteAddress) || "unknown";
112
+ this._port = (this.http2 ? this.s.session?.socket?.remotePort : this.req?.socket?.remotePort) || -1;
107
113
  this.body = "";
108
114
  this.raw_body = Buffer.alloc(0);
109
115
  this.wire_body = Buffer.alloc(0);
@@ -78,8 +78,6 @@ export class Stream {
78
78
  this.headers = this.req.headers;
79
79
  }
80
80
  // Request attributes.
81
- this._ip = this.http2 ? this.s.session.socket.remoteAddress : this.req.socket.remoteAddress;
82
- this._port = this.http2 ? this.s.session.socket.remotePort : this.req.socket.remotePort;
83
81
  this._method = this.http2 ? this.headers[':method'] : this.req.method;
84
82
  this._params = undefined;
85
83
  this._is_query_params = false;
@@ -92,6 +90,18 @@ export class Stream {
92
90
  this.finished = false;
93
91
  this.res_cookies = [];
94
92
  this.res_headers = this.http1 ? [] : {};
93
+ // Get ip and port.
94
+ const unpack_ip_header = (value) => {
95
+ if (value == null) {
96
+ return undefined;
97
+ }
98
+ return (Array.isArray(value) ? value[0] : value) || undefined;
99
+ };
100
+ this._ip = (unpack_ip_header(this.headers['x-forwarded-for'])
101
+ || unpack_ip_header(this.headers['x-real-ip'])
102
+ || (this.http2 ? this.s.session?.socket?.remoteAddress : this.req?.socket?.remoteAddress)
103
+ || "unknown");
104
+ this._port = (this.http2 ? this.s.session?.socket?.remotePort : this.req?.socket?.remotePort) || -1;
95
105
  // Read body.
96
106
  this.body = "";
97
107
  this.raw_body = Buffer.alloc(0);
@@ -78,8 +78,6 @@ export class Stream {
78
78
  this.headers = this.req.headers;
79
79
  }
80
80
  // Request attributes.
81
- this._ip = this.http2 ? this.s.session.socket.remoteAddress : this.req.socket.remoteAddress;
82
- this._port = this.http2 ? this.s.session.socket.remotePort : this.req.socket.remotePort;
83
81
  this._method = this.http2 ? this.headers[':method'] : this.req.method;
84
82
  this._params = undefined;
85
83
  this._is_query_params = false;
@@ -92,6 +90,18 @@ export class Stream {
92
90
  this.finished = false;
93
91
  this.res_cookies = [];
94
92
  this.res_headers = this.http1 ? [] : {};
93
+ // Get ip and port.
94
+ const unpack_ip_header = (value) => {
95
+ if (value == null) {
96
+ return undefined;
97
+ }
98
+ return (Array.isArray(value) ? value[0] : value) || undefined;
99
+ };
100
+ this._ip = (unpack_ip_header(this.headers['x-forwarded-for'])
101
+ || unpack_ip_header(this.headers['x-real-ip'])
102
+ || (this.http2 ? this.s.session?.socket?.remoteAddress : this.req?.socket?.remoteAddress)
103
+ || "unknown");
104
+ this._port = (this.http2 ? this.s.session?.socket?.remotePort : this.req?.socket?.remotePort) || -1;
95
105
  // Read body.
96
106
  this.body = "";
97
107
  this.raw_body = Buffer.alloc(0);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Daan van den Bergh",
3
3
  "name": "@vandenberghinc/volt",
4
- "version": "1.2.20",
4
+ "version": "1.2.22",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "types": "./backend/dist/esm/index.d.ts",