module ActionDispatch::Http::URL
def raw_host_with_port
req = Request.new 'HTTP_HOST' => 'example.com:8080'
req.raw_host_with_port # => "example.com"
req = Request.new 'HTTP_HOST' => 'example.com'
end
include ActionDispatch::Http::URL
class Request < Rack::Request
Returns the \host for this request, such as "example.com".
def raw_host_with_port if forwarded = x_forwarded_host.presence forwarded.split(/,\s?/).last else get_header('HTTP_HOST') || "#{server_name || server_addr}:#{get_header('SERVER_PORT')}" end end