code: function formatHostHeader (host, port, tls) {
    var defaultPort = tls ? 443 : 80
    var posColon = -1
  
    // For the Host header, ensure that IPv6 addresses are enclosed
    // in square brackets, as defined by URI formatting
    // https://tools.ietf.org/html/rfc3986#section-3.2.2
    if ((posColon = host.indexOf(':')) !== -1 &&
        (posColon = host.indexOf(':', posColon) !== -1) &&
        host[0] !== '[') {
      host = '[' + host + ']'
    }
  
    if (port && +port !== defaultPort) {
      host += ':' + port
    }
  
    return host
  }
docs: The following algorithm is lifted from Node core: https://github.com/nodejs/node/blob/296bfd2/lib/_http_client.js#L90-L103