Skip to content

Commit 0a6ab87

Browse files
Refactoring
1 parent 3d7f1ea commit 0a6ab87

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

node_modules/uWebSockets.js/package.json

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@
4444
"eslint-plugin-promise": "^6.0.0",
4545
"nanobench": "^2.1.1"
4646
}
47-
}
47+
}

src/Request.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ class Request extends Readable {
619619
if (this.remote_ip) return this.remote_ip
620620

621621
if (this.app_options.get('trust_proxy')) {
622-
const xForwardedFor = this.get('x-forwarded-for')
622+
const xForwardedFor = this.headers.get('x-forwarded-for')
623623
if (xForwardedFor) return (this.remote_ip = xForwardedFor.split(',')[0])
624624
}
625625

@@ -635,7 +635,7 @@ class Request extends Readable {
635635
if (this.remote_proxy_ip) return this.remote_proxy_ip
636636

637637
if (this.app_options.get('trust_proxy')) {
638-
const xForwardedFor = this.get('x-forwarded-for')
638+
const xForwardedFor = this.headers.get('x-forwarded-for')
639639
if (xForwardedFor && xForwardedFor.indexOf(',') !== -1) return (this.remote_proxy_ip = xForwardedFor.split(',')[1])
640640
}
641641

@@ -685,7 +685,7 @@ class Request extends Readable {
685685
get protocol () {
686686
// Resolves x-forwarded-proto header if trust proxy is enabled
687687
const trustProxy = this.app_options.get('trust_proxy')
688-
const xForwardedProto = this.get('x-forwarded-proto')
688+
const xForwardedProto = this.headers.get('x-forwarded-proto')
689689
if (trustProxy && xForwardedProto) return xForwardedProto.indexOf(',') !== -1 ? xForwardedProto.split(',')[0] : xForwardedProto
690690

691691
// Use uWS initially defined protocol
@@ -705,24 +705,22 @@ class Request extends Readable {
705705
* @returns {Array}
706706
*/
707707
get ips () {
708-
const clientIP = this.ip
709-
const proxyIP = this.proxy_ip
710708
const trustProxy = this.app_options.get('trust_proxy')
711-
const xForwardedFor = this.get('x-forwarded-for')
709+
const xForwardedFor = this.headers.get('x-forwarded-for')
712710
if (trustProxy && xForwardedFor) return xForwardedFor.split(',')
713711

714-
return [clientIP, proxyIP]
712+
return [this.ip, this.proxy_ip]
715713
}
716714

717715
/**
718716
* ExpressJS: Parse the "Host" header field to a hostname.
719717
*/
720718
get hostname () {
721719
const trustProxy = this.app_options.get('trust_proxy')
722-
let host = this.get('x-forwarded-host')
720+
let host = this.headers.get('x-forwarded-host')
723721

724722
if (!host || !trustProxy) {
725-
host = this.get('host')
723+
host = this.headers.get('host')
726724
} else if (host.indexOf(',') !== -1) {
727725
// Note: X-Forwarded-Host is normally only ever a
728726
// single value, but this is to be safe.

0 commit comments

Comments
 (0)