webtorrent/parse-torrent

remote() false TypeError [ERR_INVALID_PROTOCOL]

cidrmill opened this issue · 2 comments

What version of this package are you using?
9.1.3

What operating system, Node.js, and npm version?
MacOS 11.2.3
Node 15.12.0
npm 7.6.3

What happened?
parse-torrent.remote() mistakens a HTTP URL as a magnet, throwing Uncaught TypeError [ERR_INVALID_PROTOCOL]: Protocol "magnet:" not supported. Expected "http:" when passing an HTTP link to a .torrent file.

What did you expect to happen?
Parse-torrent is supposed to call the HTTP link

I found that this is caused by the HTTP endpoint throwing a 302 and redirecting to the associated magnet url.

XMLHttpRequest is currently incapable of detecting a 302 and transparently redirects to the next location. Axios, which using XMLHttpRequests behaves the same way.

This is likely a browser limitation and the resolution involves configuration changes to the webserver which in my case is not possible. Somehow I'll have to detect the next location before the redirect occurs.

I discovered a solution using NodeJS in an Electron environment with NodeIntegration enabled using Node's http library.