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

Commit

Permalink
fix: pass headers to request (#3018)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
achingbrain authored May 5, 2020
1 parent b08505d commit 3ba00f8
Show file tree
Hide file tree
Showing 99 changed files with 266 additions and 128 deletions.
2 changes: 1 addition & 1 deletion examples/circuit-relaying/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ipfs-pubsub-room": "^2.0.1"
},
"devDependencies": {
"aegir": "21.4.5",
"aegir": "^21.10.0",
"execa": "^4.0.0",
"ipfs-css": "^0.13.1",
"ipfs-http-client": "^43.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/interface-ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"ipfs-block": "^0.8.1",
"ipfs-unixfs": "^1.0.1",
"ipfs-unixfs-importer": "^2.0.0",
"ipfs-utils": "^2.2.0",
"ipfs-utils": "^2.2.2",
"ipld-dag-cbor": "^0.15.1",
"ipld-dag-pb": "^0.18.3",
"is-ipfs": "^1.0.0",
Expand All @@ -58,7 +58,7 @@
"temp-write": "^4.0.0"
},
"devDependencies": {
"aegir": "21.4.5",
"aegir": "^21.10.0",
"ipfsd-ctl": "^3.0.0"
},
"contributors": [
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"dependencies": {
"buffer": "^5.4.2",
"err-code": "^2.0.0",
"ipfs-utils": "^2.2.0"
"ipfs-utils": "^2.2.2"
},
"devDependencies": {
"aegir": "21.4.5",
"aegir": "^21.10.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"delay": "^4.3.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-http-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"form-data": "^3.0.0",
"ipfs-block": "^0.8.1",
"ipfs-core-utils": "^0.2.0",
"ipfs-utils": "^2.2.0",
"ipfs-utils": "^2.2.2",
"ipld-dag-cbor": "^0.15.1",
"ipld-dag-pb": "^0.18.3",
"ipld-raw": "^4.0.1",
Expand All @@ -67,7 +67,7 @@
"stream-to-it": "^0.2.0"
},
"devDependencies": {
"aegir": "21.4.5",
"aegir": "^21.10.0",
"browser-process-platform": "^0.1.1",
"cross-env": "^7.0.0",
"go-ipfs-dep": "0.4.23-3",
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-http-client/src/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = configure((api) => {
timeout: options.timeout,
signal: options.signal,
...(
await multipartRequest(input)
await multipartRequest(input, options.headers)
)
})

Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/bitswap/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = configure(api => {
const res = await api.post('bitswap/stat', {
searchParams: toUrlSearchParams(options),
timeout: options.timeout,
signal: options.signal
signal: options.signal,
headers: options.headers
})

return toCoreInterface(await res.json())
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/bitswap/unwant.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: typeof cid === 'string' ? cid : new CID(cid).toString(),
...options
})
}),
headers: options.headers
})

return res.json()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/bitswap/wantlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module.exports = configure(api => {
const res = await (await api.post('bitswap/wantlist', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options)
searchParams: toUrlSearchParams(options),
headers: options.headers
})).json()

return (res.Keys || []).map(k => new CID(k['/']))
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/block/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: cid.toString(),
...options
})
}),
headers: options.headers
})

return new Block(Buffer.from(await res.arrayBuffer()), cid)
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-http-client/src/block/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = configure(api => {
signal: options.signal,
searchParams: toUrlSearchParams(options),
...(
await multipartRequest(data)
await multipartRequest(data, options.headers)
)
})
res = await response.json()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/block/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = configure(api => {
arg: cid.map(cid => new CID(cid).toString()),
'stream-channels': true,
...options
})
}),
headers: options.headers
})

for await (const removed of res.ndjson()) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/block/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: new CID(cid).toString(),
...options
})
}),
headers: options.headers
})
const data = await res.json()

Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/bootstrap/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: addr,
...options
})
}),
headers: options.headers
})

return res.json()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/bootstrap/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = configure(api => {
const res = await api.post('bootstrap/list', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options)
searchParams: toUrlSearchParams(options),
headers: options.headers
})

return res.json()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/bootstrap/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: addr,
...options
})
}),
headers: options.headers
})

return res.json()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: typeof path === 'string' ? path : new CID(path).toString(),
...options
})
}),
headers: options.headers
})

yield * res.iterator()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = configure(api => {
const res = await api.post('commands', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options)
searchParams: toUrlSearchParams(options),
headers: options.headers
})

return res.json()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/config/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: key,
...options
})
}),
headers: options.headers
})
const data = await res.json()

Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/config/profiles/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: profile,
...options
})
}),
headers: options.headers
})
const data = await res.json()

Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/config/profiles/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = configure(api => {
const res = await api.post('config/profile/list', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options)
searchParams: toUrlSearchParams(options),
headers: options.headers
})

const data = await res.json()
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-http-client/src/config/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = configure(api => {
signal: options.signal,
searchParams: toUrlSearchParams(options),
...(
await multipartRequest(Buffer.from(JSON.stringify(config)))
await multipartRequest(Buffer.from(JSON.stringify(config)), options.headers)
)
})

Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/config/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ module.exports = configure(api => {
const res = await api.post('config', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(params)
searchParams: toUrlSearchParams(params),
headers: options.headers
})

return toCamel(await res.json())
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-http-client/src/dag/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = configure(api => {
signal: options.signal,
searchParams: toUrlSearchParams(options),
...(
await multipartRequest(serialized)
await multipartRequest(serialized, options.headers)
)
})
const data = await res.json()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/dag/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: path ? [cid, path].join(path.startsWith('/') ? '' : '/') : `${cid}`,
...options
})
}),
headers: options.headers
})

const data = await res.json()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/dht/find-peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: `${Buffer.isBuffer(peerId) ? new CID(peerId) : peerId}`,
...options
})
}),
headers: options.headers
})

for await (const data of res.ndjson()) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/dht/find-provs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: `${new CID(cid)}`,
...options
})
}),
headers: options.headers
})

for await (const message of res.ndjson()) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/dht/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
key: encodeBufferURIComponent(key),
...options
})
}),
headers: options.headers
})

for await (const message of res.ndjson()) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/dht/provide.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: cids.map(cid => new CID(cid).toString()),
...options
})
}),
headers: options.headers
})

for await (let message of res.ndjson()) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/dht/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = configure(api => {
value
],
...options
})
}),
headers: options.headers
})

for await (let message of res.ndjson()) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/dht/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: new CID(peerId),
...options
})
}),
headers: options.headers
})

for await (let message of res.ndjson()) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/diag/cmds.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = configure(api => {
const res = await api.post('diag/cmds', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options)
searchParams: toUrlSearchParams(options),
headers: options.headers
})

return res.json()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/diag/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = configure(api => {
const res = await api.post('diag/net', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options)
searchParams: toUrlSearchParams(options),
headers: options.headers
})
return res.json()
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/diag/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = configure(api => {
const res = await api.post('diag/sys', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options)
searchParams: toUrlSearchParams(options),
headers: options.headers
})

return res.json()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: domain,
...options
})
}),
headers: options.headers
})
const data = await res.json()

Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/files/chmod.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = configure(api => {
arg: path,
mode,
...options
})
}),
headers: options.headers
})

await res.text()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/files/cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: sources.map(src => CID.isCID(src) ? `/ipfs/${src}` : src),
...options
})
}),
headers: options.headers
})

await res.text()
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/files/flush.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = configure(api => {
searchParams: toUrlSearchParams({
arg: path,
...options
})
}),
headers: options.headers
})
const data = await res.json()

Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-http-client/src/files/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports = configure(api => {
l: options.long == null ? true : options.long,
...options,
stream: true
})
}),
headers: options.headers
})

for await (const result of res.ndjson()) {
Expand Down
Loading

0 comments on commit 3ba00f8

Please sign in to comment.