Skip to content

Commit

Permalink
dry up method checking in the request object
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Sep 29, 2010
1 parent ab0d216 commit 78ac9c2
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions actionpack/lib/action_dispatch/http/request.rb
Expand Up @@ -54,11 +54,7 @@ def key?(key)
# the application should use), this \method returns the overridden
# value, not the original.
def request_method
@request_method ||= begin
method = env["REQUEST_METHOD"]
HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
method
end
@request_method ||= check_method(env["REQUEST_METHOD"])
end

# Returns a symbol form of the #request_method
Expand All @@ -70,11 +66,7 @@ def request_method_symbol
# even if it was overridden by middleware. See #request_method for
# more information.
def method
@method ||= begin
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
@method ||= check_method(env["rack.methodoverride.original_method"] || env['REQUEST_METHOD'])
end

# Returns a symbol form of the #method
Expand Down Expand Up @@ -246,5 +238,12 @@ def authorization
def local?
LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip }
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

0 comments on commit 78ac9c2

Please sign in to comment.