@adonisjs/request
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -9,3 +9,3 @@ /// <reference types="node" /> | ||
trustProxy: (address: string, distance: number) => boolean; | ||
getIp: (request: RequestContract) => string; | ||
getIp: ((request: RequestContract) => string) | null; | ||
subdomainOffset: number; | ||
@@ -24,3 +24,2 @@ }; | ||
private _lazyAccepts; | ||
private _trustFn; | ||
protected static _macros: {}; | ||
@@ -27,0 +26,0 @@ protected static _getters: {}; |
@@ -14,2 +14,9 @@ "use strict"; | ||
const macroable_1 = require("macroable"); | ||
const utils_1 = require("@adonisjs/utils"); | ||
const $ = new utils_1.ConfigReader({ | ||
allowMethodSpoofing: false, | ||
trustProxy: proxyaddr.compile('loopback'), | ||
getIp: null, | ||
subdomainOffset: 2, | ||
}); | ||
class Request extends macroable_1.Macroable { | ||
@@ -28,3 +35,2 @@ constructor(request, response, _config) { | ||
this._lazyAccepts = null; | ||
this._trustFn = this._config.trustProxy || proxyaddr.compile('loopback'); | ||
this._parseQueryString(); | ||
@@ -87,3 +93,3 @@ } | ||
method() { | ||
if (this._config.allowMethodSpoofing && this.intended() === 'POST') { | ||
if ($.get(this._config, 'allowMethodSpoofing') && this.intended() === 'POST') { | ||
return this.input('_method', this.intended()).toUpperCase(); | ||
@@ -108,14 +114,14 @@ } | ||
ip() { | ||
const ipFn = this._config.getIp; | ||
const ipFn = $.get(this._config, 'getIp'); | ||
if (typeof (ipFn) === 'function') { | ||
return ipFn(this); | ||
} | ||
return proxyaddr(this.request, this._trustFn); | ||
return proxyaddr(this.request, $.get(this._config, 'trustProxy')); | ||
} | ||
ips() { | ||
return proxyaddr.all(this.request, this._trustFn); | ||
return proxyaddr.all(this.request, $.get(this._config, 'trustProxy')); | ||
} | ||
protocol() { | ||
const protocol = this.parsedUrl.protocol; | ||
if (!this._trustFn(this.request.connection.remoteAddress, 0)) { | ||
if (!$.get(this._config, 'trustProxy')(this.request.connection.remoteAddress, 0)) { | ||
return protocol; | ||
@@ -131,3 +137,3 @@ } | ||
let host = this.header('host'); | ||
if (this._trustFn(this.request.connection.remoteAddress, 0)) { | ||
if ($.get(this._config, 'trustProxy')(this.request.connection.remoteAddress, 0)) { | ||
host = this.header('X-Forwarded-Host') || host; | ||
@@ -147,3 +153,3 @@ } | ||
} | ||
const offset = this._config.subdomainOffset || 2; | ||
const offset = $.get(this._config, 'subdomainOffset'); | ||
const subdomains = hostname.split('.').reverse().slice(offset); | ||
@@ -150,0 +156,0 @@ if (subdomains[subdomains.length - 1] === 'www') { |
@@ -6,2 +6,13 @@ # Change Log | ||
## [1.1.3](https://github.com/adonisjs/adonis-framework/tree/master/packages/request/compare/@adonisjs/request@1.1.2...@adonisjs/request@1.1.3) (2019-01-23) | ||
### Performance Improvements | ||
* **request:** use config reader for simple config management ([c096966](https://github.com/adonisjs/adonis-framework/tree/master/packages/request/commit/c096966)) | ||
## [1.1.2](https://github.com/adonisjs/adonis-framework/tree/master/packages/request/compare/@adonisjs/request@1.1.1...@adonisjs/request@1.1.2) (2019-01-22) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@adonisjs/request", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Facade over Node.js HTTP req object", | ||
@@ -36,2 +36,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@adonisjs/utils": "^1.1.0", | ||
"accepts": "^1.3.5", | ||
@@ -58,3 +59,3 @@ "fresh": "^0.5.2", | ||
}, | ||
"gitHead": "54e1ee333c22484ad4fd114846cbc620b80f62ff" | ||
"gitHead": "bb97e711a4ced5e128cf6b8002b255383c93702d" | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14953
370
1
10
+ Added@adonisjs/utils@^1.1.0
+ Added@adonisjs/utils@1.4.4(transitive)
+ Addedrequire-all@3.0.0(transitive)