Rails 2.1 RC1
Updated Instiki to Rails 2.1 RC1 (aka 2.0.991).
This commit is contained in:
parent
14afed5893
commit
5292899c9a
971 changed files with 46318 additions and 17450 deletions
|
@ -15,7 +15,7 @@ module ActionController
|
|||
# such as { 'RAILS_ENV' => 'production' }.
|
||||
attr_reader :env
|
||||
|
||||
# The true HTTP request method as a lowercase symbol, such as :get.
|
||||
# The true HTTP request method as a lowercase symbol, such as <tt>:get</tt>.
|
||||
# UnknownHttpMethod is raised for invalid methods not listed in ACCEPTED_HTTP_METHODS.
|
||||
def request_method
|
||||
@request_method ||= begin
|
||||
|
@ -28,41 +28,43 @@ module ActionController
|
|||
end
|
||||
end
|
||||
|
||||
# The HTTP request method as a lowercase symbol, such as :get.
|
||||
# Note, HEAD is returned as :get since the two are functionally
|
||||
# The HTTP request method as a lowercase symbol, such as <tt>:get</tt>.
|
||||
# Note, HEAD is returned as <tt>:get</tt> since the two are functionally
|
||||
# equivalent from the application's perspective.
|
||||
def method
|
||||
request_method == :head ? :get : request_method
|
||||
end
|
||||
|
||||
# Is this a GET (or HEAD) request? Equivalent to request.method == :get
|
||||
# Is this a GET (or HEAD) request? Equivalent to <tt>request.method == :get</tt>.
|
||||
def get?
|
||||
method == :get
|
||||
end
|
||||
|
||||
# Is this a POST request? Equivalent to request.method == :post
|
||||
# Is this a POST request? Equivalent to <tt>request.method == :post</tt>.
|
||||
def post?
|
||||
request_method == :post
|
||||
end
|
||||
|
||||
# Is this a PUT request? Equivalent to request.method == :put
|
||||
# Is this a PUT request? Equivalent to <tt>request.method == :put</tt>.
|
||||
def put?
|
||||
request_method == :put
|
||||
end
|
||||
|
||||
# Is this a DELETE request? Equivalent to request.method == :delete
|
||||
# Is this a DELETE request? Equivalent to <tt>request.method == :delete</tt>.
|
||||
def delete?
|
||||
request_method == :delete
|
||||
end
|
||||
|
||||
# Is this a HEAD request? request.method sees HEAD as :get, so check the
|
||||
# HTTP method directly.
|
||||
# Is this a HEAD request? <tt>request.method</tt> sees HEAD as <tt>:get</tt>,
|
||||
# so check the HTTP method directly.
|
||||
def head?
|
||||
request_method == :head
|
||||
end
|
||||
|
||||
# Provides acccess to the request's HTTP headers, for example:
|
||||
# request.headers["Content-Type"] # => "text/plain"
|
||||
def headers
|
||||
@env
|
||||
@headers ||= ActionController::Http::Headers.new(@env)
|
||||
end
|
||||
|
||||
def content_length
|
||||
|
@ -111,7 +113,7 @@ module ActionController
|
|||
# end
|
||||
def format=(extension)
|
||||
parameters[:format] = extension.to_s
|
||||
format
|
||||
@format = Mime::Type.lookup_by_extension(parameters[:format])
|
||||
end
|
||||
|
||||
# Returns true if the request's "X-Requested-With" header contains
|
||||
|
@ -122,26 +124,41 @@ module ActionController
|
|||
end
|
||||
alias xhr? :xml_http_request?
|
||||
|
||||
# Which IP addresses are "trusted proxies" that can be stripped from
|
||||
# the right-hand-side of X-Forwarded-For
|
||||
TRUSTED_PROXIES = /^127\.0\.0\.1$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./i
|
||||
|
||||
# Determine originating IP address. REMOTE_ADDR is the standard
|
||||
# but will fail if the user is behind a proxy. HTTP_CLIENT_IP and/or
|
||||
# HTTP_X_FORWARDED_FOR are set by proxies so check for these before
|
||||
# falling back to REMOTE_ADDR. HTTP_X_FORWARDED_FOR may be a comma-
|
||||
# delimited list in the case of multiple chained proxies; the first is
|
||||
# the originating IP.
|
||||
#
|
||||
# Security note: do not use if IP spoofing is a concern for your
|
||||
# application. Since remote_ip checks HTTP headers for addresses forwarded
|
||||
# by proxies, the client may send any IP. remote_addr can't be spoofed but
|
||||
# also doesn't work behind a proxy, since it's always the proxy's IP.
|
||||
# HTTP_X_FORWARDED_FOR are set by proxies so check for these if
|
||||
# REMOTE_ADDR is a proxy. HTTP_X_FORWARDED_FOR may be a comma-
|
||||
# delimited list in the case of multiple chained proxies; the last
|
||||
# address which is not trusted is the originating IP.
|
||||
|
||||
def remote_ip
|
||||
return @env['HTTP_CLIENT_IP'] if @env.include? 'HTTP_CLIENT_IP'
|
||||
if TRUSTED_PROXIES !~ @env['REMOTE_ADDR']
|
||||
return @env['REMOTE_ADDR']
|
||||
end
|
||||
|
||||
if @env.include? 'HTTP_CLIENT_IP'
|
||||
if @env.include? 'HTTP_X_FORWARDED_FOR'
|
||||
# We don't know which came from the proxy, and which from the user
|
||||
raise ActionControllerError.new(<<EOM)
|
||||
IP spoofing attack?!
|
||||
HTTP_CLIENT_IP=#{@env['HTTP_CLIENT_IP'].inspect}
|
||||
HTTP_X_FORWARDED_FOR=#{@env['HTTP_X_FORWARDED_FOR'].inspect}
|
||||
EOM
|
||||
end
|
||||
return @env['HTTP_CLIENT_IP']
|
||||
end
|
||||
|
||||
if @env.include? 'HTTP_X_FORWARDED_FOR' then
|
||||
remote_ips = @env['HTTP_X_FORWARDED_FOR'].split(',').reject do |ip|
|
||||
ip.strip =~ /^unknown$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./i
|
||||
remote_ips = @env['HTTP_X_FORWARDED_FOR'].split(',')
|
||||
while remote_ips.size > 1 && TRUSTED_PROXIES =~ remote_ips.last.strip
|
||||
remote_ips.pop
|
||||
end
|
||||
|
||||
return remote_ips.first.strip unless remote_ips.empty?
|
||||
return remote_ips.last.strip
|
||||
end
|
||||
|
||||
@env['REMOTE_ADDR']
|
||||
|
@ -385,6 +402,14 @@ module ActionController
|
|||
body.blank? ? {} : Hash.from_xml(body).with_indifferent_access
|
||||
when :yaml
|
||||
YAML.load(body)
|
||||
when :json
|
||||
if body.blank?
|
||||
{}
|
||||
else
|
||||
data = ActiveSupport::JSON.decode(body)
|
||||
data = {:_json => data} unless data.is_a?(Hash)
|
||||
data.with_indifferent_access
|
||||
end
|
||||
else
|
||||
{}
|
||||
end
|
||||
|
@ -473,7 +498,7 @@ module ActionController
|
|||
when Array
|
||||
value.map { |v| get_typed_value(v) }
|
||||
else
|
||||
if value.is_a?(UploadedFile)
|
||||
if value.respond_to? :original_filename
|
||||
# Uploaded file
|
||||
if value.original_filename
|
||||
value
|
||||
|
@ -490,7 +515,6 @@ module ActionController
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
MULTIPART_BOUNDARY = %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n
|
||||
|
||||
EOL = "\015\012"
|
||||
|
@ -498,7 +522,7 @@ module ActionController
|
|||
def read_multipart(body, boundary, content_length, env)
|
||||
params = Hash.new([])
|
||||
boundary = "--" + boundary
|
||||
quoted_boundary = Regexp.quote(boundary, "n")
|
||||
quoted_boundary = Regexp.quote(boundary)
|
||||
buf = ""
|
||||
bufsize = 10 * 1024
|
||||
boundary_end=""
|
||||
|
@ -583,17 +607,16 @@ module ActionController
|
|||
else
|
||||
params[name] = [content]
|
||||
end
|
||||
break if buf.size == 0
|
||||
break if content_length == -1
|
||||
end
|
||||
raise EOFError, "bad boundary end of body part" unless boundary_end=~/--/
|
||||
|
||||
begin
|
||||
begin
|
||||
body.rewind if body.respond_to?(:rewind)
|
||||
rescue Errno::ESPIPE
|
||||
rescue Errno::ESPIPE
|
||||
# Handles exceptions raised by input streams that cannot be rewound
|
||||
# such as when using plain CGI under Apache
|
||||
end
|
||||
end
|
||||
|
||||
params
|
||||
end
|
||||
|
@ -672,6 +695,7 @@ module ActionController
|
|||
else
|
||||
top << {key => value}.with_indifferent_access
|
||||
push top.last
|
||||
value = top[key]
|
||||
end
|
||||
else
|
||||
top << value
|
||||
|
@ -679,7 +703,8 @@ module ActionController
|
|||
elsif top.is_a? Hash
|
||||
key = CGI.unescape(key)
|
||||
parent << (@top = {}) if top.key?(key) && parent.is_a?(Array)
|
||||
return top[key] ||= value
|
||||
top[key] ||= value
|
||||
return top[key]
|
||||
else
|
||||
raise ArgumentError, "Don't know what to do: top is #{top.inspect}"
|
||||
end
|
||||
|
@ -688,7 +713,7 @@ module ActionController
|
|||
end
|
||||
|
||||
def type_conflict!(klass, value)
|
||||
raise TypeError, "Conflicting types for parameter containers. Expected an instance of #{klass} but found an instance of #{value.class}. This can be caused by colliding Array and Hash parameters like qs[]=value&qs[key]=value."
|
||||
raise TypeError, "Conflicting types for parameter containers. Expected an instance of #{klass} but found an instance of #{value.class}. This can be caused by colliding Array and Hash parameters like qs[]=value&qs[key]=value. (The parameters received were #{value.inspect}.)"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue