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:
- config.action_controller.asset_host = 'https://customers.staging.gitlab.com'
- config.action_mailer.asset_host = config.action_controller.asset_host
- config.action_mailer.default_url_options[:host] = 'https://customers.staging.gitlab.com'
Proposal
We should use it as: default_url_options = { host: 'localhost', protocol: :http, port: 5000 }
ActionDispatch::Http::URL.full_url_for(options)