Skip to content

Commit 3d42884

Browse files
authored
fix(rest): httpAgent condition (#4484)
1 parent 469d624 commit 3d42884

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

docs/helpers/REST.md

+16
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ Type: [object][4]
6969
}
7070
```
7171

72+
```js
73+
{
74+
helpers: {
75+
REST: {
76+
endpoint: 'http://site.com/api',
77+
prettyPrintJson: true,
78+
httpAgent: {
79+
ca: fs.readFileSync(__dirname + '/path/to/ca.pem'),
80+
rejectUnauthorized: false,
81+
keepAlive: true
82+
}
83+
}
84+
}
85+
}
86+
```
87+
7288
## Access From Helpers
7389

7490
Send REST requests by accessing `_executeRequest` method:

lib/helper/REST.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ const config = {}
6363
* }
6464
* ```
6565
*
66+
* ```js
67+
* {
68+
* helpers: {
69+
* REST: {
70+
* endpoint: 'http://site.com/api',
71+
* prettyPrintJson: true,
72+
* httpAgent: {
73+
* ca: fs.readFileSync(__dirname + '/path/to/ca.pem'),
74+
* rejectUnauthorized: false,
75+
* keepAlive: true
76+
* }
77+
* }
78+
* }
79+
* }
80+
* ```
81+
*
6682
* ## Access From Helpers
6783
*
6884
* Send REST requests by accessing `_executeRequest` method:
@@ -101,9 +117,13 @@ class REST extends Helper {
101117

102118
// Create an agent with SSL certificate
103119
if (this.options.httpAgent) {
104-
if (!this.options.httpAgent.key || !this.options.httpAgent.cert)
120+
// if one of those keys is there, all good to go
121+
if (this.options.httpAgent.ca || this.options.httpAgent.key || this.options.httpAgent.cert) {
122+
this.httpsAgent = new Agent(this.options.httpAgent)
123+
} else {
124+
// otherwise, throws an error of httpAgent config
105125
throw Error('Please recheck your httpAgent config!')
106-
this.httpsAgent = new Agent(this.options.httpAgent)
126+
}
107127
}
108128

109129
this.axios = this.httpsAgent ? axios.create({ httpsAgent: this.httpsAgent }) : axios.create()

0 commit comments

Comments
 (0)