feat: configurable rejectUnauthorized #28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change makes it possible to configure
global-agent
to ignore certificate errors when the request-specific configuration is not provided.Problem
Axios does not allow its users to ignore SSL certificate errors, see axios/axios#535, axios/axios#1976 and other issues.
The recommended way around it is to configure Axios with an
https.Agent
with the appropriate setting:However, because of the way Axios determines whether to use a
http.Agent
or ahttps.Agent
based on the protocol of the destination url, this only works if both the proxy and the target URL follow the same, HTTPS protocol.To address the problem of Axios not supporting such protocol mismatch Global Agent could be used, but this then doesn't support ignoring certificate errors by means other than setting
NODE_TLS_REJECT_UNAUTHORIZED
to0
, which is a discouraged practice.Proposed solution
Adding a new configuration option
rejectUnauthorized
tobootstrap
routine would allow developers to provide a default setting for all the requests that go throughglobal-agent
, while allowing the more customisable HTTP clients like Sindre's got to still override it on a per-request basis:Alternatives considered
While it is possible to force Global Agent to
rejectUnauthorized
by specifyingNODE_TLS_REJECT_UNAUTHORIZED
equal0
, I'd rather avoid that as this results in a warning emitted by Node.js: