From a1bf2f96ce6f086de8519e344ee7e396ae3da9bb Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 22 Dec 2009 16:08:03 -0600 Subject: [PATCH] AD::StatusCodes support is now part of rack --- actionpack/lib/action_controller/base.rb | 2 +- actionpack/lib/action_controller/metal.rb | 2 +- .../action_controller/metal/redirecting.rb | 8 ++--- actionpack/lib/action_dispatch.rb | 1 - .../lib/action_dispatch/http/response.rb | 4 +-- .../lib/action_dispatch/http/status_codes.rb | 33 ------------------- .../middleware/show_exceptions.rb | 2 +- .../testing/assertions/response.rb | 2 +- actionpack/test/controller/render_test.rb | 4 +-- 9 files changed, 12 insertions(+), 46 deletions(-) delete mode 100644 actionpack/lib/action_dispatch/http/status_codes.rb diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index f75b6ed641..dbba69f637 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -90,7 +90,7 @@ def _normalize_options(action = nil, options = {}, &blk) end if options[:status] - options[:status] = ActionDispatch::StatusCodes[options[:status]] + options[:status] = Rack::Utils.status_code(options[:status]) end options[:update] = blk if block_given? diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 93a19f8f93..b436de9878 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -69,7 +69,7 @@ def location=(url) end def status=(status) - @_status = ActionDispatch::StatusCodes[status] + @_status = Rack::Utils.status_code(status) end # :api: private diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index 39dc23024c..7a2f9a6fc5 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -58,18 +58,18 @@ def redirect_to(options = {}, response_status = {}) #:doc: logger.info("Redirected to #{location}") if logger && logger.info? end - + private def _extract_redirect_to_status(options, response_status) status = if options.is_a?(Hash) && options.key?(:status) - ActionDispatch::StatusCodes[options.delete(:status)] + Rack::Utils.status_code(options.delete(:status)) elsif response_status.key?(:status) - ActionDispatch::StatusCodes[response_status[:status]] + Rack::Utils.status_code(response_status[:status]) else 302 end end - + def _compute_redirect_to_location(options) case options # The scheme name consist of a letter followed by any combination of diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb index 48b5652a89..ed04980ab0 100644 --- a/actionpack/lib/action_dispatch.rb +++ b/actionpack/lib/action_dispatch.rb @@ -37,7 +37,6 @@ module ActionDispatch autoload_under 'http' do autoload :Request autoload :Response - autoload :StatusCodes end deferrable do diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 6dc563264f..8524bbd993 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -60,7 +60,7 @@ def cache_control end def status=(status) - @status = ActionDispatch::StatusCodes[status] + @status = Rack::Utils.status_code(status) end # The response code of the request @@ -74,7 +74,7 @@ def code end def message - StatusCodes::STATUS_CODES[@status] + Rack::Utils::HTTP_STATUS_CODES[@status] end alias_method :status_message, :message diff --git a/actionpack/lib/action_dispatch/http/status_codes.rb b/actionpack/lib/action_dispatch/http/status_codes.rb deleted file mode 100644 index 3d6ee685ea..0000000000 --- a/actionpack/lib/action_dispatch/http/status_codes.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'active_support/inflector' - -module ActionDispatch - module StatusCodes #:nodoc: - STATUS_CODES = Rack::Utils::HTTP_STATUS_CODES.merge({ - 102 => "Processing", - 207 => "Multi-Status", - 226 => "IM Used", - 422 => "Unprocessable Entity", - 423 => "Locked", - 424 => "Failed Dependency", - 426 => "Upgrade Required", - 507 => "Insufficient Storage", - 510 => "Not Extended" - }).freeze - - def self.[](status) - if status.is_a?(Symbol) - SYMBOL_TO_STATUS_CODE[status] || 500 - else - status.to_i - end - end - - # Provides a symbol-to-fixnum lookup for converting a symbol (like - # :created or :not_implemented) into its corresponding HTTP status - # code (like 200 or 501). - SYMBOL_TO_STATUS_CODE = STATUS_CODES.inject({}) { |hash, (code, message)| - hash[ActiveSupport::Inflector.underscore(message.gsub(/ /, "")).to_sym] = code - hash - }.freeze - end -end diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb index bd87764f5b..5c7f78b0e4 100644 --- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb @@ -101,7 +101,7 @@ def local_request?(request) end def status_code(exception) - ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[@@rescue_responses[exception.class.name]] + Rack::Utils.status_code(@@rescue_responses[exception.class.name]) end def render(status, body) diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 501a7c4dfb..5686bbdbde 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -28,7 +28,7 @@ def assert_response(type, message = nil) assert_block("") { true } # to count the assertion elsif type.is_a?(Fixnum) && @response.response_code == type assert_block("") { true } # to count the assertion - elsif type.is_a?(Symbol) && @response.response_code == ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[type] + elsif type.is_a?(Symbol) && @response.response_code == Rack::Utils::SYMBOL_TO_STATUS_CODE[type] assert_block("") { true } # to count the assertion else assert_block(build_message(message, "Expected response to be a , but was ", type, @response.response_code)) { false } diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index f26b15d2e0..54f2739d38 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1125,7 +1125,7 @@ def test_head_with_symbolic_status assert !@response.headers.include?('Content-Length') assert_response :no_content - ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code| + Rack::Utils::SYMBOL_TO_STATUS_CODE.each do |status, code| get :head_with_symbolic_status, :status => status.to_s assert_equal code, @response.response_code assert_response status @@ -1133,7 +1133,7 @@ def test_head_with_symbolic_status end def test_head_with_integer_status - ActionDispatch::StatusCodes::STATUS_CODES.each do |code, message| + Rack::Utils::HTTP_STATUS_CODES.each do |code, message| get :head_with_integer_status, :status => code.to_s assert_equal message, @response.message end -- GitLab