Skip to content

Commit

Permalink
Store original HTTP method in MethodOverride middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrosby authored and leahneukirchen committed Jan 6, 2009
1 parent f981f3b commit e908d26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rack/methodoverride.rb
Expand Up @@ -16,6 +16,7 @@ def call(env)
env[HTTP_METHOD_OVERRIDE_HEADER]
method = method.to_s.upcase
if HTTP_METHODS.include?(method)
env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
env["REQUEST_METHOD"] = method
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/spec_rack_methodoverride.rb
Expand Up @@ -47,4 +47,14 @@

req.env["REQUEST_METHOD"].should.equal "POST"
end

specify "should store the original REQUEST_METHOD prior to overriding" do
env = Rack::MockRequest.env_for("/",
:method => "POST",
:input => "_method=options")
app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
req = app.call(env)

req.env["rack.methodoverride.original_method"].should.equal "POST"
end
end

0 comments on commit e908d26

Please sign in to comment.