aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/request.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_dispatch/http/request.rb')
-rwxr-xr-xactionpack/lib/action_dispatch/http/request.rb52
1 files changed, 20 insertions, 32 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index 325f2cdca4..a2c14f7ea2 100755
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -6,7 +6,6 @@ require 'active_support/memoizable'
module ActionDispatch
class Request < Rack::Request
- extend ActiveSupport::Memoizable
%w[ AUTH_TYPE GATEWAY_INTERFACE
PATH_TRANSLATED REMOTE_HOST
@@ -34,7 +33,6 @@ module ActionDispatch
def request_method
HTTP_METHOD_LOOKUP[super] || raise(ActionController::UnknownHttpMethod, "#{super}, accepted HTTP methods are #{HTTP_METHODS.to_sentence}")
end
- memoize :request_method
# Returns the HTTP request \method used for action processing as a
# lowercase symbol, such as <tt>:post</tt>. (Unlike #request_method, this
@@ -76,7 +74,6 @@ module ActionDispatch
def headers
Http::Headers.new(@env)
end
- memoize :headers
# Returns the content length of the request as an integer.
def content_length
@@ -88,38 +85,39 @@ module ActionDispatch
# For backward compatibility, the post \format is extracted from the
# X-Post-Data-Format HTTP header if present.
def content_type
- if @env['CONTENT_TYPE'] =~ /^([^,\;]*)/
- Mime::Type.lookup($1.strip.downcase)
- else
- nil
+ @content_type ||= begin
+ if @env['CONTENT_TYPE'] =~ /^([^,\;]*)/
+ Mime::Type.lookup($1.strip.downcase)
+ else
+ nil
+ end
end
end
- memoize :content_type
-
+
# Returns the accepted MIME type for the request.
def accepts
- header = @env['HTTP_ACCEPT'].to_s.strip
+ @accepts ||= begin
+ header = @env['HTTP_ACCEPT'].to_s.strip
- fallback = xhr? ? Mime::JS : Mime::HTML
+ fallback = xhr? ? Mime::JS : Mime::HTML
- if header.empty?
- [content_type, fallback, Mime::ALL].compact
- else
- ret = Mime::Type.parse(header)
- if ret.last == Mime::ALL
- ret.insert(-2, fallback)
+ if header.empty?
+ [content_type, fallback, Mime::ALL].compact
+ else
+ ret = Mime::Type.parse(header)
+ if ret.last == Mime::ALL
+ ret.insert(-2, fallback)
+ end
+ ret
end
- ret
end
end
- memoize :accepts
-
+
def if_modified_since
if since = env['HTTP_IF_MODIFIED_SINCE']
Time.rfc2822(since) rescue nil
end
end
- memoize :if_modified_since
def if_none_match
env['HTTP_IF_NONE_MATCH']
@@ -171,7 +169,7 @@ module ActionDispatch
def formats
@formats =
if ActionController::Base.use_accept_header
- ret = Array(Mime[parameters[:format]] || accepts)
+ Array(Mime[parameters[:format]] || accepts)
else
[format]
end
@@ -262,25 +260,21 @@ EOM
@env['REMOTE_ADDR']
end
- memoize :remote_ip
# 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
- memoize :server_software
# Returns the complete URL used for this request.
def url
protocol + host_with_port + request_uri
end
- memoize :url
# Returns 'https://' if this is an SSL request and 'http://' otherwise.
def protocol
ssl? ? 'https://' : 'http://'
end
- memoize :protocol
# Is this an SSL request?
def ssl?
@@ -300,14 +294,12 @@ EOM
def host
raw_host_with_port.sub(/:\d+$/, '')
end
- memoize :host
# Returns a \host:\port string for this request, such as "example.com" or
# "example.com:8080".
def host_with_port
"#{host}#{port_string}"
end
- memoize :host_with_port
# Returns the port number of this request as an integer.
def port
@@ -317,7 +309,6 @@ EOM
standard_port
end
end
- memoize :port
# Returns the standard \port number for this request's protocol.
def standard_port
@@ -355,7 +346,6 @@ EOM
def query_string
@env['QUERY_STRING'].present? ? @env['QUERY_STRING'] : (@env['REQUEST_URI'].split('?', 2)[1] || '')
end
- memoize :query_string
# Returns the request URI, accounting for server idiosyncrasies.
# WEBrick includes the full URL. IIS leaves REQUEST_URI blank.
@@ -381,7 +371,6 @@ EOM
end
end
end
- memoize :request_uri
# Returns the interpreted \path to requested resource after all the installation
# directory of this application was taken into account.
@@ -390,7 +379,6 @@ EOM
path.sub!(/\A#{ActionController::Base.relative_url_root}/, '')
path
end
- memoize :path
# Read the request \body. This is useful for web services that need to
# work with raw requests directly.