Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rest): validation of httpAgent config #4484

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/helpers/REST.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ Type: [object][4]
}
```

```js
{
helpers: {
REST: {
endpoint: 'http://site.com/api',
prettyPrintJson: true,
httpAgent: {
ca: fs.readFileSync(__dirname + '/path/to/ca.pem'),
rejectUnauthorized: false,
keepAlive: true
}
}
}
}
```

## Access From Helpers

Send REST requests by accessing `_executeRequest` method:
Expand Down
24 changes: 22 additions & 2 deletions lib/helper/REST.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ const config = {}
* }
* ```
*
* ```js
* {
* helpers: {
* REST: {
* endpoint: 'http://site.com/api',
* prettyPrintJson: true,
* httpAgent: {
* ca: fs.readFileSync(__dirname + '/path/to/ca.pem'),
* rejectUnauthorized: false,
* keepAlive: true
* }
* }
* }
* }
* ```
*
* ## Access From Helpers
*
* Send REST requests by accessing `_executeRequest` method:
Expand Down Expand Up @@ -101,9 +117,13 @@ class REST extends Helper {

// Create an agent with SSL certificate
if (this.options.httpAgent) {
if (!this.options.httpAgent.key || !this.options.httpAgent.cert)
// if one of those keys is there, all good to go
if (this.options.httpAgent.ca || this.options.httpAgent.key || this.options.httpAgent.cert) {
this.httpsAgent = new Agent(this.options.httpAgent)
} else {
// otherwise, throws an error of httpAgent config
throw Error('Please recheck your httpAgent config!')
this.httpsAgent = new Agent(this.options.httpAgent)
}
}

this.axios = this.httpsAgent ? axios.create({ httpsAgent: this.httpsAgent }) : axios.create()
Expand Down
Loading