Returns the domain part of a host, such as “rubyonrails.org“ in “www.rubyonrails.org“. You can specify a different tld_length, such as 2 to catch rubyonrails.co.uk in “www.rubyonrails.co.uk“.
# File lib/action_dispatch/http/url.rb, line 78 78: def domain(tld_length = 1) 79: return nil unless named_host?(host) 80: 81: host.split('.').last(1 + tld_length).join('.') 82: end
Returns the host for this request, such as example.com.
# File lib/action_dispatch/http/url.rb, line 34 34: def host 35: raw_host_with_port.sub(/:\d+$/, '') 36: end
Returns a host:port string for this request, such as “example.com“ or “example.com:8080”.
# File lib/action_dispatch/http/url.rb, line 40 40: def host_with_port 41: "#{host}#{port_string}" 42: end
Returns the port number of this request as an integer.
# File lib/action_dispatch/http/url.rb, line 45 45: def port 46: if raw_host_with_port =~ /:(\d+)$/ 47: $1.to_i 48: else 49: standard_port 50: end 51: end
Returns a port suffix like “:8080” if the port number of this request is not the default HTTP port 80 or HTTPS port 443.
# File lib/action_dispatch/http/url.rb, line 68 68: def port_string 69: port == standard_port ? '' : ":#{port}" 70: end
Returns ‘https://’ if this is an SSL request and ‘http://’ otherwise.
# File lib/action_dispatch/http/url.rb, line 15 15: def protocol 16: ssl? ? 'https://' : 'http://' 17: end
Returns the host for this request, such as “example.com“.
# File lib/action_dispatch/http/url.rb, line 25 25: def raw_host_with_port 26: if forwarded = env["HTTP_X_FORWARDED_HOST"] 27: forwarded.split(/,\s?/).last 28: else 29: env['HTTP_HOST'] || "#{env['SERVER_NAME'] || env['SERVER_ADDR']}:#{env['SERVER_PORT']}" 30: end 31: end
Returns the request URI, accounting for server idiosyncrasies. WEBrick includes the full URL. IIS leaves REQUEST_URI blank.
# File lib/action_dispatch/http/url.rb, line 100 100: def request_uri 101: ActiveSupport::Deprecation.warn "Using #request_uri is deprecated. Use fullpath instead.", caller 102: fullpath 103: end
Returns ‘https’ if this is an SSL request and ‘http’ otherwise.
# File lib/action_dispatch/http/url.rb, line 10 10: def scheme 11: ssl? ? 'https' : 'http' 12: end
# File lib/action_dispatch/http/url.rb, line 72 72: def server_port 73: @env['SERVER_PORT'].to_i 74: end
Is this an SSL request?
# File lib/action_dispatch/http/url.rb, line 20 20: def ssl? 21: @env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https' 22: end
Returns the standard port number for this request’s protocol.
# File lib/action_dispatch/http/url.rb, line 54 54: def standard_port 55: case protocol 56: when 'https://' then 443 57: else 80 58: end 59: end
Returns whether this request is using the standard port
# File lib/action_dispatch/http/url.rb, line 62 62: def standard_port? 63: port == standard_port 64: end
# File lib/action_dispatch/http/url.rb, line 94 94: def subdomain(tld_length = 1) 95: subdomains(tld_length).join('.') 96: end
Returns all the subdomains as an array, so ["dev", "www"] would be returned for “dev.www.rubyonrails.org“. You can specify a different tld_length, such as 2 to catch ["www"] instead of ["www", "rubyonrails"] in “www.rubyonrails.co.uk“.
# File lib/action_dispatch/http/url.rb, line 88 88: def subdomains(tld_length = 1) 89: return [] unless named_host?(host) 90: parts = host.split('.') 91: parts[0..-(tld_length+2)] 92: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.