Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added Request#url that returns the complete URL used for the request …
…[DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6316 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Mar 4, 2007
1 parent 4568c1d commit e0179c1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 50 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Added Request#url that returns the complete URL used for the request [DHH]

* Extract dynamic scaffolding into a plugin. #7700 [Josh Peek]

* Added user/password options for url_for to add http authentication in a URL [DHH]
Expand Down
108 changes: 58 additions & 50 deletions actionpack/lib/action_controller/request.rb
Expand Up @@ -9,11 +9,6 @@ class AbstractRequest
# such as { 'RAILS_ENV' => 'production' }.
attr_reader :env

# Returns both GET and POST parameters in a single hash.
def parameters
@parameters ||= request_parameters.update(query_parameters).update(path_parameters).with_indifferent_access
end

# Returns the HTTP request method as a lowercase symbol (:get, for example). Note, HEAD is returned as :get
# since the two are supposedly to be functionaly equivilent for all purposes except that HEAD won't return a response
# body (which Rails also takes care of elsewhere).
Expand Down Expand Up @@ -126,6 +121,56 @@ def remote_ip
@env['REMOTE_ADDR']
end

# Returns the lowercase name of the HTTP server software.
def server_software
(@env['SERVER_SOFTWARE'] && /^([a-zA-Z]+)/ =~ @env['SERVER_SOFTWARE']) ? $1.downcase : nil
end


# Returns the complete URL used for this request
def url
request.protocol + request.host_with_port + request.request_uri
end

# Return 'https://' if this is an SSL request and 'http://' otherwise.
def protocol
ssl? ? 'https://' : 'http://'
end

# Is this an SSL request?
def ssl?
@env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https'
end

# Returns the host for this request, such as example.com.
def host
end

# Returns a host:port string for this request, such as example.com or
# example.com:8080.
def host_with_port
host + port_string
end

# Returns the port number of this request as an integer.
def port
@port_as_int ||= @env['SERVER_PORT'].to_i
end

# Returns the standard port number for this request's protocol
def standard_port
case protocol
when 'https://' then 443
else 80
end
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.
def port_string
(port == standard_port) ? '' : ":#{port}"
end

# Returns the domain part of a host, such as rubyonrails.org in "www.rubyonrails.org". You can specify
# a different <tt>tld_length</tt>, such as 2 to catch rubyonrails.co.uk in "www.rubyonrails.co.uk".
def domain(tld_length = 1)
Expand All @@ -143,13 +188,6 @@ def subdomains(tld_length = 1)
parts[0..-(tld_length+2)]
end

# Receive the raw post data.
# This is useful for services such as REST, XMLRPC and SOAP
# which communicate over HTTP POST but don't use the traditional parameter format.
def raw_post
@env['RAW_POST_DATA']
end

# Return the request URI, accounting for server idiosyncracies.
# WEBrick includes the full URL. IIS leaves REQUEST_URI blank.
def request_uri
Expand All @@ -168,16 +206,6 @@ def request_uri
end
end

# Return 'https://' if this is an SSL request and 'http://' otherwise.
def protocol
ssl? ? 'https://' : 'http://'
end

# Is this an SSL request?
def ssl?
@env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https'
end

# Returns the interpreted path to requested resource after all the installation directory of this application was taken into account
def path
path = (uri = request_uri) ? uri.split('?').first : ''
Expand All @@ -202,29 +230,17 @@ def relative_url_root
end
end

# Returns the port number of this request as an integer.
def port
@port_as_int ||= @env['SERVER_PORT'].to_i
end

# Returns the standard port number for this request's protocol
def standard_port
case protocol
when 'https://' then 443
else 80
end
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.
def port_string
(port == standard_port) ? '' : ":#{port}"
# Receive the raw post data.
# This is useful for services such as REST, XMLRPC and SOAP
# which communicate over HTTP POST but don't use the traditional parameter format.
def raw_post
@env['RAW_POST_DATA']
end

# Returns a host:port string for this request, such as example.com or
# example.com:8080.
def host_with_port
host + port_string
# Returns both GET and POST parameters in a single hash.
def parameters
@parameters ||= request_parameters.update(query_parameters).update(path_parameters).with_indifferent_access
end

def path_parameters=(parameters) #:nodoc:
Expand All @@ -246,10 +262,6 @@ def path_parameters
@path_parameters ||= {}
end

# Returns the lowercase name of the HTTP server software.
def server_software
(@env['SERVER_SOFTWARE'] && /^([a-zA-Z]+)/ =~ @env['SERVER_SOFTWARE']) ? $1.downcase : nil
end

#--
# Must be implemented in the concrete request
Expand All @@ -260,10 +272,6 @@ def query_parameters #:nodoc:
def request_parameters #:nodoc:
end

# Returns the host for this request, such as example.com.
def host
end

def cookies #:nodoc:
end

Expand Down

0 comments on commit e0179c1

Please sign in to comment.