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).

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.