Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webtorrent setting a custom User-Agent in requests #1530

Open
C0nw0nk opened this issue Oct 24, 2018 · 15 comments
Open

Webtorrent setting a custom User-Agent in requests #1530

C0nw0nk opened this issue Oct 24, 2018 · 15 comments
Labels

Comments

@C0nw0nk
Copy link

@C0nw0nk C0nw0nk commented Oct 24, 2018

I see webtorrent sends a custom user agent in all its request to my server checking nginx logs.

WebTorrent/0.102.4 (https://webtorrent.io)

Isit possible to include a feature to set my own custom user agent in javascript. The benefits of that could be awesome for my server expecting a specific useragent instead in requests and also for sha1 url's etc.

torrent.setUserAgent('WebTorrent/0.102.4 (https://webtorrent.io)') //can change modify and set a custom user agent for requests from webtorrent to your server
@SilentBot1

This comment has been minimized.

Copy link
Member

@SilentBot1 SilentBot1 commented Oct 24, 2018

Hey @C0nw0nk,

Currently the user agent is hard coded for all webseeds, tracker, and metadata requests, though it would be easy to implement a changeable user agent. Would you be looking for changing all instances of the user agent including requests made to trackers or only the user agents included with WebSeed / Metadata requests?

All the best.

@C0nw0nk

This comment has been minimized.

Copy link
Author

@C0nw0nk C0nw0nk commented Oct 24, 2018

@C0nw0nk

This comment has been minimized.

Copy link
Author

@C0nw0nk C0nw0nk commented Oct 24, 2018

@SilentBot1 Ontop of what i previously wrote does webtorrent when requesting the .torrent file from my server can that send a custom header or modify the user-agent too ?

@jimmywarting

This comment has been minimized.

Copy link
Contributor

@jimmywarting jimmywarting commented Oct 25, 2018

Borrowing this thread a lite, But i'm wondering how you can get the user-agent of another peer...

@SilentBot1

This comment has been minimized.

Copy link
Member

@SilentBot1 SilentBot1 commented Oct 25, 2018

@C0nw0nk, the implementation I wrote which can be seen here, I'll not send a PR yet as it seems not all your requirements are there, it sets one blanket user-agent for all requests, meaning it is presented to the tracker, .torrent server (metadata server) and webseed.

If you are wanting to be able to specify all three separately, that could also be done, though for your use case I would recommend using a combination of a user-agent and request origin or even a custom middleware with tokens.

Hey @jimmywarting,

The user-agent is only presented in http(s) requests to trackers, webseeds and the metadata server so currently it's not possible to get another peers user-agent, you could possibly create a bittorrent-protocol extension to exchange user-agents with remote peers if it's needed depending on what you are doing.

@jimmywarting

This comment has been minimized.

Copy link
Contributor

@jimmywarting jimmywarting commented Oct 25, 2018

Don't really need it but it would have been interesting to know and see what other torrent clients others are using. Other torrent clients are able to display it so.

@SilentBot1

This comment has been minimized.

Copy link
Member

@SilentBot1 SilentBot1 commented Oct 25, 2018

@jimmywarting sorry, I thought you were asking about the user-agent.

The peerId of a peer should contain the version and software being used in the from of a prefix, though with WebTorrent going above version 0.100.0 there is a issue with the prefix as the current version 0.102.4 shows as the prefix -WW0002-.

@jimmywarting

This comment has been minimized.

Copy link
Contributor

@jimmywarting jimmywarting commented Oct 25, 2018

@SilentBot1 Oh, so the peerid prefix is how they figure that out.
I thought torrent clients figure that out by getting others peers user-agent string or something like that

Thanks mate

@untitledlt

This comment has been minimized.

Copy link
Contributor

@untitledlt untitledlt commented Oct 26, 2018

Would be great if we could add basic Auth, cookies or custom headers as many trackers requires authentication.

@SilentBot1

This comment has been minimized.

Copy link
Member

@SilentBot1 SilentBot1 commented Oct 26, 2018

Hey @untitledlt,

I agree this would be a useful feature to be able to assign individual headers for http trackers. This would require changes in at least two modules torrent-discovery, bittorrent-tracker and likely this module too, I'll have a look and start throwing something together in the next few days.

@guanzo

This comment has been minimized.

Copy link
Contributor

@guanzo guanzo commented Oct 28, 2018

Related to: #1507

Webtorrent should allow users to transform any part of the http request. Any library that makes http requests should allow the requests to be open for extension, as every user's needs are different.

Beware that in Chrome, the user-agent that Webtorrent sets is overwritten with:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36

@C0nw0nk

This comment has been minimized.

Copy link
Author

@C0nw0nk C0nw0nk commented Oct 28, 2018

#1530 (comment) It would be better as a feature like that for custom headers to be added but then again the way @SilentBot1 has added it to the torrent options.

client = new WebTorrent([opts])

If opts is specified, then the default options (shown below) will be overridden.

{
maxConns: Number, // Max number of connections per torrent (default=55)
nodeId: String|Buffer, // DHT protocol node ID (default=randomly generated)
peerId: String|Buffer, // Wire protocol peer ID (default=randomly generated)
tracker: Boolean|Object, // Enable trackers (default=true), or options object for Tracker
dht: Boolean|Object, // Enable DHT (default=true), or options object for DHT
webSeeds: Boolean // Enable BEP19 web seeds (default=true)
userAgent: String // Custom user agent to present on webseed, tracker and metadata requests
}

A customheader addition that allows us to specify either one or multiple custom headers to send in requests would go down so well.

@C0nw0nk

This comment has been minimized.

Copy link
Author

@C0nw0nk C0nw0nk commented Oct 30, 2018

Any update on when this will be in the mainline version for us to use :) ?

@C0nw0nk

This comment has been minimized.

Copy link
Author

@C0nw0nk C0nw0nk commented Oct 30, 2018

It also just occured to me isit possible to overwrite any request header that would be useful for authentication reasons between my HTML pages javascript and my server.

Like editing the Origin request header to be what my server allows only as an Origin for authentication purposes.

I would customise these.

Origin:
Referer:
User-Agent:
X-Custom-Header:
@C0nw0nk

This comment has been minimized.

Copy link
Author

@C0nw0nk C0nw0nk commented Nov 3, 2018

Interesting find here. As was mentioned here #1530 (comment) Google Chrome does NOT respect webtorrent changing the User-Agent it will still force its own User-Agent on all requests to torrents and webseeds etc.

As for a custom header X-Custom-Header: I assume it would be fine and ok still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.