Skip to content

Commit 879e2f9

Browse files
authored
fix: use https agent for https requests (#3490)
Fixes regression introduced in #3474 - if we make https requests, use a https agent.
1 parent 31949ac commit 879e2f9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"ipfs-utils/src/files/glob-source": false,
2020
"go-ipfs": false,
2121
"ipfs-core-utils/src/files/normalise-input": "ipfs-core-utils/src/files/normalise-input/index.browser.js",
22-
"http": false
22+
"http": false,
23+
"https": false
2324
},
2425
"typesVersions": {
2526
"*": {

src/lib/core.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const HTTP = require('ipfs-utils/src/http')
88
const merge = require('merge-options')
99
const toUrlString = require('ipfs-core-utils/src/to-url-string')
1010
const http = require('http')
11+
const https = require('https')
1112

1213
const DEFAULT_PROTOCOL = isBrowser || isWebWorker ? location.protocol : 'http'
1314
const DEFAULT_HOST = isBrowser || isWebWorker ? location.hostname : 'localhost'
@@ -49,7 +50,9 @@ const normalizeOptions = (options = {}) => {
4950
}
5051

5152
if (isNode) {
52-
agent = opts.agent || new http.Agent({
53+
const Agent = url.protocol.startsWith('https') ? https.Agent : http.Agent
54+
55+
agent = opts.agent || new Agent({
5356
keepAlive: true,
5457
// Similar to browsers which limit connections to six per host
5558
maxSockets: 6
@@ -116,7 +119,8 @@ const parseTimeout = (value) => {
116119
}
117120

118121
/**
119-
* @typedef {import('http').Agent} Agent
122+
* @typedef {import('http').Agent} HttpAgent
123+
* @typedef {import('https').Agent} HttpsAgent
120124
*
121125
* @typedef {Object} ClientOptions
122126
* @property {string} [host]
@@ -129,7 +133,7 @@ const parseTimeout = (value) => {
129133
* @property {object} [ipld]
130134
* @property {any[]} [ipld.formats] - An array of additional [IPLD formats](https://github.com/ipld/interface-ipld-format) to support
131135
* @property {(format: string) => Promise<any>} [ipld.loadFormat] - an async function that takes the name of an [IPLD format](https://github.com/ipld/interface-ipld-format) as a string and should return the implementation of that codec
132-
* @property {Agent} [agent] - A [http.Agent](https://nodejs.org/api/http.html#http_class_http_agent) used to control connection persistence and reuse for HTTP clients (only supported in node.js)
136+
* @property {HttpAgent|HttpsAgent} [agent] - A [http.Agent](https://nodejs.org/api/http.html#http_class_http_agent) used to control connection persistence and reuse for HTTP clients (only supported in node.js)
133137
*/
134138
class Client extends HTTP {
135139
/**

0 commit comments

Comments
 (0)