提交 a1bf2f96 编写于 作者: J Joshua Peek

AD::StatusCodes support is now part of rack

上级 17b60530
...@@ -90,7 +90,7 @@ def _normalize_options(action = nil, options = {}, &blk) ...@@ -90,7 +90,7 @@ def _normalize_options(action = nil, options = {}, &blk)
end end
if options[:status] if options[:status]
options[:status] = ActionDispatch::StatusCodes[options[:status]] options[:status] = Rack::Utils.status_code(options[:status])
end end
options[:update] = blk if block_given? options[:update] = blk if block_given?
......
...@@ -69,7 +69,7 @@ def location=(url) ...@@ -69,7 +69,7 @@ def location=(url)
end end
def status=(status) def status=(status)
@_status = ActionDispatch::StatusCodes[status] @_status = Rack::Utils.status_code(status)
end end
# :api: private # :api: private
......
...@@ -58,18 +58,18 @@ def redirect_to(options = {}, response_status = {}) #:doc: ...@@ -58,18 +58,18 @@ def redirect_to(options = {}, response_status = {}) #:doc:
logger.info("Redirected to #{location}") if logger && logger.info? logger.info("Redirected to #{location}") if logger && logger.info?
end end
private private
def _extract_redirect_to_status(options, response_status) def _extract_redirect_to_status(options, response_status)
status = if options.is_a?(Hash) && options.key?(: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) elsif response_status.key?(:status)
ActionDispatch::StatusCodes[response_status[:status]] Rack::Utils.status_code(response_status[:status])
else else
302 302
end end
end end
def _compute_redirect_to_location(options) def _compute_redirect_to_location(options)
case options case options
# The scheme name consist of a letter followed by any combination of # The scheme name consist of a letter followed by any combination of
......
...@@ -37,7 +37,6 @@ module ActionDispatch ...@@ -37,7 +37,6 @@ module ActionDispatch
autoload_under 'http' do autoload_under 'http' do
autoload :Request autoload :Request
autoload :Response autoload :Response
autoload :StatusCodes
end end
deferrable do deferrable do
......
...@@ -60,7 +60,7 @@ def cache_control ...@@ -60,7 +60,7 @@ def cache_control
end end
def status=(status) def status=(status)
@status = ActionDispatch::StatusCodes[status] @status = Rack::Utils.status_code(status)
end end
# The response code of the request # The response code of the request
...@@ -74,7 +74,7 @@ def code ...@@ -74,7 +74,7 @@ def code
end end
def message def message
StatusCodes::STATUS_CODES[@status] Rack::Utils::HTTP_STATUS_CODES[@status]
end end
alias_method :status_message, :message alias_method :status_message, :message
......
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
...@@ -101,7 +101,7 @@ def local_request?(request) ...@@ -101,7 +101,7 @@ def local_request?(request)
end end
def status_code(exception) 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 end
def render(status, body) def render(status, body)
......
...@@ -28,7 +28,7 @@ def assert_response(type, message = nil) ...@@ -28,7 +28,7 @@ def assert_response(type, message = nil)
assert_block("") { true } # to count the assertion assert_block("") { true } # to count the assertion
elsif type.is_a?(Fixnum) && @response.response_code == type elsif type.is_a?(Fixnum) && @response.response_code == type
assert_block("") { true } # to count the assertion 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 assert_block("") { true } # to count the assertion
else else
assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false } assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false }
......
...@@ -1125,7 +1125,7 @@ def test_head_with_symbolic_status ...@@ -1125,7 +1125,7 @@ def test_head_with_symbolic_status
assert !@response.headers.include?('Content-Length') assert !@response.headers.include?('Content-Length')
assert_response :no_content 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 get :head_with_symbolic_status, :status => status.to_s
assert_equal code, @response.response_code assert_equal code, @response.response_code
assert_response status assert_response status
...@@ -1133,7 +1133,7 @@ def test_head_with_symbolic_status ...@@ -1133,7 +1133,7 @@ def test_head_with_symbolic_status
end end
def test_head_with_integer_status 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 get :head_with_integer_status, :status => code.to_s
assert_equal message, @response.message assert_equal message, @response.message
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册