Class Index [+]

Quicksearch

ActionDispatch::Http::URL

Public Instance Methods

domain(tld_length = 1) click to toggle source

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
host() click to toggle source

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
host_with_port() click to toggle source

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
port() click to toggle source

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
port_string() click to toggle source

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
protocol() click to toggle source

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
raw_host_with_port() click to toggle source

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
request_uri() click to toggle source

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
scheme() click to toggle source

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
server_port() click to toggle source
    # File lib/action_dispatch/http/url.rb, line 72
72:       def server_port
73:         @env['SERVER_PORT'].to_i
74:       end
ssl?() click to toggle source

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
standard_port() click to toggle source

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
standard_port?() click to toggle source

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
subdomain(tld_length = 1) click to toggle source
    # File lib/action_dispatch/http/url.rb, line 94
94:       def subdomain(tld_length = 1)
95:         subdomains(tld_length).join('.')
96:       end
subdomains(tld_length = 1) click to toggle source

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
url() click to toggle source

Returns the complete URL used for this request.

   # File lib/action_dispatch/http/url.rb, line 5
5:       def url
6:         protocol + host_with_port + fullpath
7:       end

Private Instance Methods

named_host?(host) click to toggle source
     # File lib/action_dispatch/http/url.rb, line 107
107:       def named_host?(host)
108:         !(host.nil? || /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host))
109:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.