aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/verb_piggybacking.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-12-23 13:36:05 -0600
committerJoshua Peek <josh@joshpeek.com>2008-12-23 13:36:05 -0600
commit9c1e48eaea921efa67fbeed1ff1876dc710f8fd2 (patch)
tree9afb77428da5d309664e9e09960e95a5277faa98 /actionpack/lib/action_controller/verb_piggybacking.rb
parent3562d54d18bf6c87384436c63383666617a2a1eb (diff)
downloadrails-9c1e48eaea921efa67fbeed1ff1876dc710f8fd2.tar.gz
rails-9c1e48eaea921efa67fbeed1ff1876dc710f8fd2.tar.bz2
rails-9c1e48eaea921efa67fbeed1ff1876dc710f8fd2.zip
ActionController::VerbPiggybacking middleware
Diffstat (limited to 'actionpack/lib/action_controller/verb_piggybacking.rb')
-rw-r--r--actionpack/lib/action_controller/verb_piggybacking.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/verb_piggybacking.rb b/actionpack/lib/action_controller/verb_piggybacking.rb
new file mode 100644
index 0000000000..86cde304a0
--- /dev/null
+++ b/actionpack/lib/action_controller/verb_piggybacking.rb
@@ -0,0 +1,24 @@
+module ActionController
+ # TODO: Use Rack::MethodOverride when it is released
+ class VerbPiggybacking
+ HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS)
+
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ if env["REQUEST_METHOD"] == "POST"
+ req = Request.new(env)
+ if method = (req.parameters[:_method] || env["HTTP_X_HTTP_METHOD_OVERRIDE"])
+ method = method.to_s.upcase
+ if HTTP_METHODS.include?(method)
+ env["REQUEST_METHOD"] = method
+ end
+ end
+ end
+
+ @app.call(env)
+ end
+ end
+end