Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit b9d8dd8

Browse files
committed
fix: pass headers to request
Somewhere along the line we stopped passing headers to the underlying request library which means people can't use http auth etc to try to secure their API servers. Fixes #3017 Depends on: - [ ] ipfs/js-ipfs-utils#41
1 parent f443f0a commit b9d8dd8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+237
-102
lines changed

packages/interface-ipfs-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"ipfs-block": "^0.8.1",
4040
"ipfs-unixfs": "^1.0.1",
4141
"ipfs-unixfs-importer": "^2.0.0",
42-
"ipfs-utils": "^2.2.0",
42+
"ipfs-utils": "ipfs/js-ipfs-utils#fix/respect-headers",
4343
"ipld-dag-cbor": "^0.15.1",
4444
"ipld-dag-pb": "^0.18.3",
4545
"is-ipfs": "^1.0.0",

packages/ipfs-core-utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"dependencies": {
3131
"buffer": "^5.4.2",
3232
"err-code": "^2.0.0",
33-
"ipfs-utils": "^2.2.0"
33+
"ipfs-utils": "ipfs/js-ipfs-utils#fix/respect-headers"
3434
},
3535
"devDependencies": {
3636
"aegir": "21.4.5",

packages/ipfs-http-client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"form-data": "^3.0.0",
4848
"ipfs-block": "^0.8.1",
4949
"ipfs-core-utils": "^0.2.0",
50-
"ipfs-utils": "^2.2.0",
50+
"ipfs-utils": "ipfs/js-ipfs-utils#fix/respect-headers",
5151
"ipld-dag-cbor": "^0.15.1",
5252
"ipld-dag-pb": "^0.18.3",
5353
"ipld-raw": "^4.0.1",

packages/ipfs-http-client/src/add.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = configure((api) => {
1919
timeout: options.timeout,
2020
signal: options.signal,
2121
...(
22-
await multipartRequest(input)
22+
await multipartRequest(input, options.headers)
2323
)
2424
})
2525

packages/ipfs-http-client/src/bitswap/stat.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = configure(api => {
1010
const res = await api.post('bitswap/stat', {
1111
searchParams: toUrlSearchParams(options),
1212
timeout: options.timeout,
13-
signal: options.signal
13+
signal: options.signal,
14+
headers: options.headers
1415
})
1516

1617
return toCoreInterface(await res.json())

packages/ipfs-http-client/src/bitswap/unwant.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = configure(api => {
1212
searchParams: toUrlSearchParams({
1313
arg: typeof cid === 'string' ? cid : new CID(cid).toString(),
1414
...options
15-
})
15+
}),
16+
headers: options.headers
1617
})
1718

1819
return res.json()

packages/ipfs-http-client/src/bitswap/wantlist.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ module.exports = configure(api => {
1313
const res = await (await api.post('bitswap/wantlist', {
1414
timeout: options.timeout,
1515
signal: options.signal,
16-
searchParams: toUrlSearchParams(options)
16+
searchParams: toUrlSearchParams(options),
17+
headers: options.headers
1718
})).json()
1819

1920
return (res.Keys || []).map(k => new CID(k['/']))

packages/ipfs-http-client/src/block/get.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ module.exports = configure(api => {
1616
searchParams: toUrlSearchParams({
1717
arg: cid.toString(),
1818
...options
19-
})
19+
}),
20+
headers: options.headers
2021
})
2122

2223
return new Block(Buffer.from(await res.arrayBuffer()), cid)

packages/ipfs-http-client/src/block/put.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = configure(api => {
3939
signal: options.signal,
4040
searchParams: toUrlSearchParams(options),
4141
...(
42-
await multipartRequest(data)
42+
await multipartRequest(data, options.headers)
4343
)
4444
})
4545
res = await response.json()

packages/ipfs-http-client/src/block/rm.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module.exports = configure(api => {
1717
arg: cid.map(cid => new CID(cid).toString()),
1818
'stream-channels': true,
1919
...options
20-
})
20+
}),
21+
headers: options.headers
2122
})
2223

2324
for await (const removed of res.ndjson()) {

packages/ipfs-http-client/src/block/stat.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = configure(api => {
1212
searchParams: toUrlSearchParams({
1313
arg: new CID(cid).toString(),
1414
...options
15-
})
15+
}),
16+
headers: options.headers
1617
})
1718
const data = await res.json()
1819

packages/ipfs-http-client/src/bootstrap/add.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module.exports = configure(api => {
1717
searchParams: toUrlSearchParams({
1818
arg: addr,
1919
...options
20-
})
20+
}),
21+
headers: options.headers
2122
})
2223

2324
return res.json()

packages/ipfs-http-client/src/bootstrap/list.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module.exports = configure(api => {
88
const res = await api.post('bootstrap/list', {
99
timeout: options.timeout,
1010
signal: options.signal,
11-
searchParams: toUrlSearchParams(options)
11+
searchParams: toUrlSearchParams(options),
12+
headers: options.headers
1213
})
1314

1415
return res.json()

packages/ipfs-http-client/src/bootstrap/rm.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module.exports = configure(api => {
1717
searchParams: toUrlSearchParams({
1818
arg: addr,
1919
...options
20-
})
20+
}),
21+
headers: options.headers
2122
})
2223

2324
return res.json()

packages/ipfs-http-client/src/cat.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = configure(api => {
1212
searchParams: toUrlSearchParams({
1313
arg: typeof path === 'string' ? path : new CID(path).toString(),
1414
...options
15-
})
15+
}),
16+
headers: options.headers
1617
})
1718

1819
yield * res.iterator()

packages/ipfs-http-client/src/commands.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module.exports = configure(api => {
88
const res = await api.post('commands', {
99
timeout: options.timeout,
1010
signal: options.signal,
11-
searchParams: toUrlSearchParams(options)
11+
searchParams: toUrlSearchParams(options),
12+
headers: options.headers
1213
})
1314

1415
return res.json()

packages/ipfs-http-client/src/config/get.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module.exports = configure(api => {
1717
searchParams: toUrlSearchParams({
1818
arg: key,
1919
...options
20-
})
20+
}),
21+
headers: options.headers
2122
})
2223
const data = await res.json()
2324

packages/ipfs-http-client/src/config/profiles/apply.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module.exports = configure(api => {
1111
searchParams: toUrlSearchParams({
1212
arg: profile,
1313
...options
14-
})
14+
}),
15+
headers: options.headers
1516
})
1617
const data = await res.json()
1718

packages/ipfs-http-client/src/config/profiles/list.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module.exports = configure(api => {
99
const res = await api.post('config/profile/list', {
1010
timeout: options.timeout,
1111
signal: options.signal,
12-
searchParams: toUrlSearchParams(options)
12+
searchParams: toUrlSearchParams(options),
13+
headers: options.headers
1314
})
1415

1516
const data = await res.json()

packages/ipfs-http-client/src/config/replace.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = configure(api => {
1212
signal: options.signal,
1313
searchParams: toUrlSearchParams(options),
1414
...(
15-
await multipartRequest(Buffer.from(JSON.stringify(config)))
15+
await multipartRequest(Buffer.from(JSON.stringify(config)), options.headers)
1616
)
1717
})
1818

packages/ipfs-http-client/src/config/set.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ module.exports = configure(api => {
2929
const res = await api.post('config', {
3030
timeout: options.timeout,
3131
signal: options.signal,
32-
searchParams: toUrlSearchParams(params)
32+
searchParams: toUrlSearchParams(params),
33+
headers: options.headers
3334
})
3435

3536
return toCamel(await res.json())

packages/ipfs-http-client/src/dag/put.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = configure(api => {
4848
signal: options.signal,
4949
searchParams: toUrlSearchParams(options),
5050
...(
51-
await multipartRequest(serialized)
51+
await multipartRequest(serialized, options.headers)
5252
)
5353
})
5454
const data = await res.json()

packages/ipfs-http-client/src/dag/resolve.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module.exports = configure(api => {
1717
searchParams: toUrlSearchParams({
1818
arg: path ? [cid, path].join(path.startsWith('/') ? '' : '/') : `${cid}`,
1919
...options
20-
})
20+
}),
21+
headers: options.headers
2122
})
2223

2324
const data = await res.json()

packages/ipfs-http-client/src/dht/find-peer.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module.exports = configure(api => {
1515
searchParams: toUrlSearchParams({
1616
arg: `${Buffer.isBuffer(peerId) ? new CID(peerId) : peerId}`,
1717
...options
18-
})
18+
}),
19+
headers: options.headers
1920
})
2021

2122
for await (const data of res.ndjson()) {

packages/ipfs-http-client/src/dht/find-provs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module.exports = configure(api => {
1414
searchParams: toUrlSearchParams({
1515
arg: `${new CID(cid)}`,
1616
...options
17-
})
17+
}),
18+
headers: options.headers
1819
})
1920

2021
for await (const message of res.ndjson()) {

packages/ipfs-http-client/src/dht/get.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ module.exports = configure(api => {
1818
searchParams: toUrlSearchParams({
1919
key: encodeBufferURIComponent(key),
2020
...options
21-
})
21+
}),
22+
headers: options.headers
2223
})
2324

2425
for await (const message of res.ndjson()) {

packages/ipfs-http-client/src/dht/provide.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ module.exports = configure(api => {
1616
searchParams: toUrlSearchParams({
1717
arg: cids.map(cid => new CID(cid).toString()),
1818
...options
19-
})
19+
}),
20+
headers: options.headers
2021
})
2122

2223
for await (let message of res.ndjson()) {

packages/ipfs-http-client/src/dht/put.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module.exports = configure(api => {
1717
value
1818
],
1919
...options
20-
})
20+
}),
21+
headers: options.headers
2122
})
2223

2324
for await (let message of res.ndjson()) {

packages/ipfs-http-client/src/dht/query.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module.exports = configure(api => {
1414
searchParams: toUrlSearchParams({
1515
arg: new CID(peerId),
1616
...options
17-
})
17+
}),
18+
headers: options.headers
1819
})
1920

2021
for await (let message of res.ndjson()) {

packages/ipfs-http-client/src/diag/cmds.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module.exports = configure(api => {
88
const res = await api.post('diag/cmds', {
99
timeout: options.timeout,
1010
signal: options.signal,
11-
searchParams: toUrlSearchParams(options)
11+
searchParams: toUrlSearchParams(options),
12+
headers: options.headers
1213
})
1314

1415
return res.json()

packages/ipfs-http-client/src/diag/net.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module.exports = configure(api => {
88
const res = await api.post('diag/net', {
99
timeout: options.timeout,
1010
signal: options.signal,
11-
searchParams: toUrlSearchParams(options)
11+
searchParams: toUrlSearchParams(options),
12+
headers: options.headers
1213
})
1314
return res.json()
1415
}

packages/ipfs-http-client/src/diag/sys.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module.exports = configure(api => {
88
const res = await api.post('diag/sys', {
99
timeout: options.timeout,
1010
signal: options.signal,
11-
searchParams: toUrlSearchParams(options)
11+
searchParams: toUrlSearchParams(options),
12+
headers: options.headers
1213
})
1314

1415
return res.json()

packages/ipfs-http-client/src/dns.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module.exports = configure(api => {
1111
searchParams: toUrlSearchParams({
1212
arg: domain,
1313
...options
14-
})
14+
}),
15+
headers: options.headers
1516
})
1617
const data = await res.json()
1718

packages/ipfs-http-client/src/files/chmod.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = configure(api => {
1212
arg: path,
1313
mode,
1414
...options
15-
})
15+
}),
16+
headers: options.headers
1617
})
1718

1819
await res.text()

packages/ipfs-http-client/src/files/cp.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module.exports = configure(api => {
1515
searchParams: toUrlSearchParams({
1616
arg: sources.map(src => CID.isCID(src) ? `/ipfs/${src}` : src),
1717
...options
18-
})
18+
}),
19+
headers: options.headers
1920
})
2021

2122
await res.text()

packages/ipfs-http-client/src/files/flush.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module.exports = configure(api => {
1717
searchParams: toUrlSearchParams({
1818
arg: path,
1919
...options
20-
})
20+
}),
21+
headers: options.headers
2122
})
2223
const data = await res.json()
2324

packages/ipfs-http-client/src/files/ls.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ module.exports = configure(api => {
2525
l: options.long == null ? true : options.long,
2626
...options,
2727
stream: true
28-
})
28+
}),
29+
headers: options.headers
2930
})
3031

3132
for await (const result of res.ndjson()) {

packages/ipfs-http-client/src/files/mkdir.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module.exports = configure(api => {
1111
searchParams: toUrlSearchParams({
1212
arg: path,
1313
...options
14-
})
14+
}),
15+
headers: options.headers
1516
})
1617

1718
await res.text()

packages/ipfs-http-client/src/files/mv.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module.exports = configure(api => {
1515
searchParams: toUrlSearchParams({
1616
arg: sources.map(src => CID.isCID(src) ? `/ipfs/${src}` : src),
1717
...options
18-
})
18+
}),
19+
headers: options.headers
1920
})
2021

2122
await res.text()

packages/ipfs-http-client/src/files/read.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module.exports = configure(api => {
1414
arg: path,
1515
count: options.count || options.length,
1616
...options
17-
})
17+
}),
18+
headers: options.headers
1819
})
1920

2021
for await (const chunk of toIterable(res.body)) {

0 commit comments

Comments
 (0)