Use URI to build URIs and hostname= to wrap ipv6 addresses in brackets.

See: https://bugs.ruby-lang.org/issues/3788
Related: https://www.ietf.org/rfc/rfc2732.txt
There is no disadvantage.  Clients shouldn't need to know that ::1 needs to become http://[::1] in URIs.  We'll see what they say.  For now, this workaround is good enough.