diff options
Diffstat (limited to 'actionpack')
8 files changed, 41 insertions, 36 deletions
diff --git a/actionpack/lib/action_controller/metal/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb index 5674eef67b..64f6f7cf51 100644 --- a/actionpack/lib/action_controller/metal/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb @@ -90,8 +90,10 @@ module ActionController #:nodoc: # # class FooController < ApplicationController # protect_from_forgery except: :index + # end # # You can disable forgery protection on controller by skipping the verification before_action: + # # skip_before_action :verify_authenticity_token # # Valid Options: diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 903dba3eb4..130ba61786 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -540,7 +540,7 @@ module ActionController end alias_method :delete_if, :reject! - # Return values that were assigned to the given +keys+. Note that all the + # Returns values that were assigned to the given +keys+. Note that all the # +Hash+ objects will be converted to <tt>ActionController::Parameters</tt>. def values_at(*keys) convert_value_to_parameters(@parameters.values_at(*keys)) diff --git a/actionpack/lib/action_dispatch/http/cache.rb b/actionpack/lib/action_dispatch/http/cache.rb index 1d0a6b6eb3..6b25ee9a70 100644 --- a/actionpack/lib/action_dispatch/http/cache.rb +++ b/actionpack/lib/action_dispatch/http/cache.rb @@ -59,7 +59,7 @@ module ActionDispatch end def last_modified? - have_header? LAST_MODIFIED + has_header? LAST_MODIFIED end def last_modified=(utc_time) @@ -73,7 +73,7 @@ module ActionDispatch end def date? - have_header? DATE + has_header? DATE end def date=(utc_time) diff --git a/actionpack/lib/action_dispatch/http/filter_parameters.rb b/actionpack/lib/action_dispatch/http/filter_parameters.rb index 9c0f39f2e7..9dcab79c3a 100644 --- a/actionpack/lib/action_dispatch/http/filter_parameters.rb +++ b/actionpack/lib/action_dispatch/http/filter_parameters.rb @@ -30,12 +30,12 @@ module ActionDispatch @filtered_path = nil end - # Return a hash of parameters with all sensitive data replaced. + # Returns a hash of parameters with all sensitive data replaced. def filtered_parameters @filtered_parameters ||= parameter_filter.filter(parameters) end - # Return a hash of request.env with all sensitive data replaced. + # Returns a hash of request.env with all sensitive data replaced. def filtered_env @filtered_env ||= env_filter.filter(@env) end diff --git a/actionpack/lib/action_dispatch/http/headers.rb b/actionpack/lib/action_dispatch/http/headers.rb index 9a3aaca3f0..12f81dc1a5 100644 --- a/actionpack/lib/action_dispatch/http/headers.rb +++ b/actionpack/lib/action_dispatch/http/headers.rb @@ -49,6 +49,11 @@ module ActionDispatch @req.set_header env_name(key), value end + # Add a value to a multivalued header like Vary or Accept-Encoding. + def add(key, value) + @req.add_header env_name(key), value + end + def key?(key) @req.has_header? env_name(key) end diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index f6f63f1f32..a27ff67114 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -156,31 +156,11 @@ module ActionDispatch # :nodoc: yield self if block_given? end - def have_header?(key); headers.key? key; end + def has_header?(key); headers.key? key; end def get_header(key); headers[key]; end def set_header(key, v); headers[key] = v; end def delete_header(key); headers.delete key; end - # Add a header that may have multiple values. - # - # Example: - # response.add_header 'Vary', 'Accept' - # response.add_header 'Vary', 'Accept-Encoding' - # response.add_header 'Vary', 'Cookie' - # - # assert_equal 'Accept,Accept-Encoding,Cookie', response.get_header 'Vary' - # - # http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2 - def add_header(key, v) - if v.nil? - get_header key - elsif have_header? key - set_header key, "#{get_header key},#{v}" - else - set_header key, v - end - end - def await_commit synchronize do @cv.wait_until { @committed } diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb index 79600b654b..7f1ef121b7 100644 --- a/actionpack/test/dispatch/header_test.rb +++ b/actionpack/test/dispatch/header_test.rb @@ -42,6 +42,24 @@ class HeaderTest < ActiveSupport::TestCase assert_equal "127.0.0.1", @headers["HTTP_HOST"] end + test "add to multivalued headers" do + # Sets header when not present + @headers.add 'Foo', '1' + assert_equal '1', @headers['Foo'] + + # Ignores nil values + @headers.add 'Foo', nil + assert_equal '1', @headers['Foo'] + + # Converts value to string + @headers.add 'Foo', 1 + assert_equal '1,1', @headers['Foo'] + + # Case-insensitive + @headers.add 'fOo', 2 + assert_equal '1,1,2', @headers['foO'] + end + test "headers can contain numbers" do @headers["Content-MD5"] = "Q2hlY2sgSW50ZWdyaXR5IQ==" diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 3de0863bdf..c4f52fcc3a 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -298,10 +298,10 @@ class ResponseHeadersTest < ActiveSupport::TestCase @response.set_header 'Foo', '1' end - test 'have_header?' do - assert @response.have_header? 'Foo' - assert_not @response.have_header? 'foo' - assert_not @response.have_header? nil + test 'has_header?' do + assert @response.has_header? 'Foo' + assert_not @response.has_header? 'foo' + assert_not @response.has_header? nil end test 'get_header' do @@ -312,11 +312,11 @@ class ResponseHeadersTest < ActiveSupport::TestCase test 'set_header' do assert_equal '2', @response.set_header('Foo', '2') - assert @response.have_header?('Foo') + assert @response.has_header?('Foo') assert_equal '2', @response.get_header('Foo') assert_nil @response.set_header('Foo', nil) - assert @response.have_header?('Foo') + assert @response.has_header?('Foo') assert_nil @response.get_header('Foo') end @@ -324,10 +324,10 @@ class ResponseHeadersTest < ActiveSupport::TestCase assert_nil @response.delete_header(nil) assert_nil @response.delete_header('foo') - assert @response.have_header?('Foo') + assert @response.has_header?('Foo') assert_equal '1', @response.delete_header('Foo') - assert_not @response.have_header?('Foo') + assert_not @response.has_header?('Foo') end test 'add_header' do @@ -341,12 +341,12 @@ class ResponseHeadersTest < ActiveSupport::TestCase # Add nil to a nonexistent header assert_nil @response.add_header('Bar', nil) - assert_not @response.have_header?('Bar') + assert_not @response.has_header?('Bar') assert_nil @response.get_header('Bar') # Add a value to a nonexistent header assert_equal '1', @response.add_header('Bar', '1') - assert @response.have_header?('Bar') + assert @response.has_header?('Bar') assert_equal '1', @response.get_header('Bar') end end |