module ActionDispatch::Http::URL

def build_host_url(host, port, protocol, options, path)

def build_host_url(host, port, protocol, options, path)
  if match = host.match(HOST_REGEXP)
    protocol ||= match[1] unless protocol == false
    host       = match[2]
    port       = match[3] unless options.key? :port
  end
  protocol = normalize_protocol protocol
  host     = normalize_host(host, options)
  result = protocol.dup
  if options[:user] && options[:password]
    result << "#{Rack::Utils.escape(options[:user])}:#{Rack::Utils.escape(options[:password])}@"
  end
  result << host
  normalize_port(port, protocol) { |normalized_port|
    result << ":#{normalized_port}"
  }
  result.concat path
end