Skip to content

default_url_options[:host] has absolute_url assigned instead of host

Problem

@mkaeppler started discussion

In hosts.rb initializer we are assigning absolute URLs to a host field. The host is localhost or customers.gitlab.com, it's not a URL

This is not correct I think. Here are the method docs from ActionDispatch:

      # * <tt>:protocol</tt> - The protocol to connect to. Defaults to <tt>"http"</tt>.
      # * <tt>:host</tt> - Specifies the host the link should be targeted at.

e.g.:

      #    url_for controller: 'tasks', action: 'testing', host: 'somehost.org', port: '8080'
      #    # => 'http://somehost.org:8080/tasks/testing'

It's used in various places in the codebase as absolute_url: https://gitlab.com/search?search=Rails.application.routes.default_url_options%5B%3Ahost%5D&nav_source=navbar&project_id=2670515&group_id=9970&search_code=true&repository_ref=main

The same is for other host values that has absolute_url assigned:

Proposal

We should use it as: default_url_options = { host: 'localhost', protocol: :http, port: 5000 }

ActionDispatch::Http::URL.full_url_for(options)

=> "http://localhost:5000"

Result

Next steps (if any)

How will we measure success?