@alicloud/pop-core
Advanced tools
Comparing version 1.5.4 to 1.6.0
@@ -41,3 +41,4 @@ // Type definitions for [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~] | ||
accessKeySecret: string; | ||
opts: object; | ||
} | ||
} |
@@ -109,2 +109,4 @@ 'use strict'; | ||
} | ||
this.opts = config.opts || {}; | ||
@@ -120,3 +122,5 @@ var httpModule = this.endpoint.startsWith('https://') | ||
request(action, params = {}, opts = {}) { | ||
// 1. compose params | ||
// 1. compose params and opts | ||
opts = Object.assign({}, this.opts, opts); | ||
// format action until formatAction is false | ||
@@ -123,0 +127,0 @@ if (opts.formatAction !== false) { |
@@ -63,3 +63,3 @@ 'use strict'; | ||
this.host = url.parse(this.endpoint).hostname; | ||
this.opts = config.opts; | ||
var httpModule = this.host.startsWith('https://') ? require('https') : require('http'); | ||
@@ -173,3 +173,3 @@ this.keepAliveAgent = new httpModule.Agent({ | ||
data: postBody | ||
}, opts); | ||
}, this.opts, opts); | ||
@@ -176,0 +176,0 @@ return httpx.request(url, options).then((response) => { |
{ | ||
"name": "@alicloud/pop-core", | ||
"version": "1.5.4", | ||
"version": "1.6.0", | ||
"description": "AliCloud POP SDK core", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -72,3 +72,31 @@ # @alicloud/pop-core | ||
### Custom opts | ||
We offer two ways to customize request opts. | ||
One way is passing opts through the Client constructor. You should treat opts passed through the constructor as default custom opts, because all requests will use this opts. | ||
```js | ||
var client = new RPCClient({ | ||
accessKeyId: '<accessKeyId>', | ||
accessKeySecret: '<accessKeySecret>', | ||
endpoint: '<endpoint>', | ||
apiVersion: '<apiVersion>', | ||
opts: { | ||
timeout: 3000 | ||
} | ||
}); | ||
``` | ||
Another way is passing opts through the function's parameter. You should use this way when you want to just pass opts in specific functions. | ||
```js | ||
client.request(action, params, { | ||
timeout: 3000 | ||
}); | ||
``` | ||
When both ways are used, opts will be merged. But for the opt with the same key, the opts provided by the function parameter overrides the opts provided by the constructor. | ||
## License | ||
The MIT License |
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
17355
400
102