提交 78ac9c2b 编写于 作者: A Aaron Patterson

dry up method checking in the request object

上级 ab0d216b
...@@ -54,11 +54,7 @@ def key?(key) ...@@ -54,11 +54,7 @@ def key?(key)
# the application should use), this \method returns the overridden # the application should use), this \method returns the overridden
# value, not the original. # value, not the original.
def request_method def request_method
@request_method ||= begin @request_method ||= check_method(env["REQUEST_METHOD"])
method = env["REQUEST_METHOD"]
HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
method
end
end end
# Returns a symbol form of the #request_method # Returns a symbol form of the #request_method
...@@ -70,11 +66,7 @@ def request_method_symbol ...@@ -70,11 +66,7 @@ def request_method_symbol
# even if it was overridden by middleware. See #request_method for # even if it was overridden by middleware. See #request_method for
# more information. # more information.
def method def method
@method ||= begin @method ||= check_method(env["rack.methodoverride.original_method"] || env['REQUEST_METHOD'])
method = env["rack.methodoverride.original_method"] || env['REQUEST_METHOD']
HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
method
end
end end
# Returns a symbol form of the #method # Returns a symbol form of the #method
...@@ -246,5 +238,12 @@ def authorization ...@@ -246,5 +238,12 @@ def authorization
def local? def local?
LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip } LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip }
end end
private
def check_method(name)
HTTP_METHOD_LOOKUP[name] || raise(ActionController::UnknownHttpMethod, "#{name}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
name
end
end end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册