Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
piliugin-anton committed Jun 17, 2022
1 parent 3d7f1ea commit 0a6ab87
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
7 changes: 3 additions & 4 deletions node_modules/uWebSockets.js/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
"eslint-plugin-promise": "^6.0.0",
"nanobench": "^2.1.1"
}
}
}
16 changes: 7 additions & 9 deletions src/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ class Request extends Readable {
if (this.remote_ip) return this.remote_ip

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

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

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

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

// Use uWS initially defined protocol
Expand All @@ -705,24 +705,22 @@ class Request extends Readable {
* @returns {Array}
*/
get ips () {
const clientIP = this.ip
const proxyIP = this.proxy_ip
const trustProxy = this.app_options.get('trust_proxy')
const xForwardedFor = this.get('x-forwarded-for')
const xForwardedFor = this.headers.get('x-forwarded-for')
if (trustProxy && xForwardedFor) return xForwardedFor.split(',')

return [clientIP, proxyIP]
return [this.ip, this.proxy_ip]
}

/**
* ExpressJS: Parse the "Host" header field to a hostname.
*/
get hostname () {
const trustProxy = this.app_options.get('trust_proxy')
let host = this.get('x-forwarded-host')
let host = this.headers.get('x-forwarded-host')

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

0 comments on commit 0a6ab87

Please sign in to comment.