code: func getHostAndProtocol(r *http.Request, allowForwarded bool) (host, proto string) {
  	if r.TLS != nil {
  		proto = "https"
  	} else {
  		proto = "http"
  	}
  
  	host = r.Host
  
  	if !allowForwarded {
  		return
  	}
  
  	if h := r.Header.Get("X-Forwarded-Host"); h != "" {
  		host = h
  	}
  
  	if h := r.Header.Get("X-Forwarded-Proto"); h == "http" || h == "https" {
  		proto = h
  	}
  
  	if h := r.Header.Get("Forwarded"); h != "" {
  		if r := reForwardedHost.FindStringSubmatch(h); len(r) == 2 {
  			host = r[1]
  		}
  
  		if r := reForwardedProto.FindStringSubmatch(h); len(r) == 2 {
  			proto = r[1]
  		}
  	}
  
  	return
  }
docs: // getHostAndProtocol extracts the host and used protocol (either HTTP or HTTPS)
  // from the given request. If `allowForwarded` is set, the X-Forwarded-Host,
  // X-Forwarded-Proto and Forwarded headers will also be checked to
  // support proxies.