0

I have a function to add files in js-ipfs via URL.

async function addFile(url) {
  try {
    for await (const file of node.add(urlSource(url))) {
      console.log('Hash for ' + url.substring(url.lastIndexOf('/') + 1));
    }
  }
  catch(e) {
    console.error('Problem downloading: ' + e.toString());
  }
}

Some URLs that I pass in work great, while others will serve a file only to certain user agents. Is there a way to specify a custom user agent of "Wget/" on the HTTP GET requests done by IPFS urlSource?

Edit: After poking around the source of js-ipfs a bit, it looks like it's using node-fetch to make the request. I tried changing the line to:

for await (const file of node.add(urlSource(url, {"headers": ["User-Agent", "Wget/"]}))) {

and

for await (const file of node.add(urlSource(url, {"headers": {"User-Agent": "Wget/"}}))) {

based off of the node-fetch docs, but no dice. Webhook.site still shows my requests having a user-agent of node-fetch/1.0 (+https://github.com/bitinn/node-fetch).

xd1936
  • 1,038
  • 2
  • 9
  • 27

1 Answers1

0

User achingbrain on the IPFS forums pointed out that the options object is currently not passed into the http constructor. I have submitted a pull request to modify this behavior.

xd1936
  • 1,038
  • 2
  • 9
  • 27