-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
libp2phttp.Host implements RoundTripper #2840
Conversation
|
||
testCases := []string{ | ||
// Version that has an http-path. Will uncomment when we get the http-path changes in go-multiaddr | ||
// "multiaddr:" + serverHost.Addrs()[0].String() + "/http-path/hello", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! ❤️
// if true, we won't add the server's addresses to the peerstore. This | ||
// should only be set when creating the struct. | ||
skipAddAddrs bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on why we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It really doesn't matter, but it saves us the synchronization overhead of the addrsAdded sync.Once
call.
if parsed.sni != parsed.host { | ||
// We have a different host and SNI (e.g. using an IP address but specifying a SNI) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work with /dns
addrs?
Do we need something like: https://github.com/libp2p/go-libp2p/blob/master/p2p/transport/websocket/websocket.go#L123 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes /dns
works. Roundtripper handles this implicitly. Fails if the server doesn't support the SNI. Example: /dns/example.com/tls/sni/example.net/http
works, but /dns/example.net/tls/sni/notexample.com/http
fails.
After working on the js-libp2p API for libp2p+HTTP, I realized it's quite natural to make an HTTP request given a multiaddr URI (who would've guessed?).
This change makes using the HTTP client with libp2p easier and more natural. Instead of having to create a specialized roundtripper for each server, you can now have a single
http.Client
that can make requests to multiple servers. The usage feels very familiar to the classic HTTP api. You can now do this: