Add support for /https, /http, /wss API multiaddresses.
Lotus API endpoint are by default expressed as multiaddresses (i.e. lotus auth api-info) which end in /http, although they can be provided as standard URLs too. There is an inconsistency here because despite the "http" part, Lotus will use "ws" protocol. This lets lotus default to "ws" but honor whatever the user puts in the multiaddress (i.e. /dns4/my.lotus.node/tcp/443/https) would work now using https, where before it uses "ws".
This commit is contained in:
parent
4ad8d85b13
commit
c6ed6a0d65
@ -44,7 +44,22 @@ func (a APIInfo) DialArgs() (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return "ws://" + addr + "/rpc/v0", nil
|
||||
protocol := "ws"
|
||||
|
||||
// If the user specifies the multiaddress as
|
||||
// /something/tcp/1234/http or/something/tcp/1234/https
|
||||
// or /something/tcp/1234/wss then honor that.
|
||||
for _, p := range []int{
|
||||
multiaddr.P_HTTP,
|
||||
multiaddr.P_HTTPS,
|
||||
multiaddr.P_WSS,
|
||||
} {
|
||||
if _, err := ma.ValueForProtocol(p); err == nil {
|
||||
protocol = multiaddr.ProtocolWithCode(p).Name
|
||||
break
|
||||
}
|
||||
}
|
||||
return protocol + "://" + addr + "/rpc/v0", nil
|
||||
}
|
||||
|
||||
_, err = url.Parse(a.Addr)
|
||||
|
Loading…
Reference in New Issue
Block a user