1
mirror of https://github.com/rclone/rclone synced 2024-11-19 20:07:15 +01:00

rc: prefer actual listener address if using ":port" or "addr:0" only

Before this change rclone would turn `localhost:8888` into
`127.0.0.1:8888` which apparently does not work with some browsers.

See: https://github.com/rclone/rclone-webui-react/issues/117
This commit is contained in:
Nick Craig-Wood 2020-12-18 12:55:12 +00:00
parent bdc2278a30
commit 73bb9322f5

View File

@ -379,8 +379,10 @@ func (s *Server) URL() string {
proto = "https"
}
addr := s.Opt.ListenAddr
if s.listener != nil {
// prefer actual listener address; required if using 0-port
// prefer actual listener address if using ":port" or "addr:0"
useActualAddress := addr == "" || addr[0] == ':' || addr[len(addr)-1] == ':' || strings.HasSuffix(addr, ":0")
if s.listener != nil && useActualAddress {
// use actual listener address; required if using 0-port
// (i.e. port assigned by operating system)
addr = s.listener.Addr().String()
}