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
Then we could avoid the variable assignment and just do:
```ruby
def base_uri
  require 'uri'
  URI::Generic.build(:scheme => scheme.to_s, :host => server, :port => port).to_s
end
```