Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 28 lines (23 sloc) 0.715 kB
e4ad5c7 @josh Add MethodOverride middleware to allow browsers to fake PUT and DELET…
josh authored
1 module Rack
2 class MethodOverride
889e2bc @rkh add support for PATCH verb to Rack::MethodOverride
rkh authored
3 HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS PATCH)
e4ad5c7 @josh Add MethodOverride middleware to allow browsers to fake PUT and DELET…
josh authored
4
8b8690b @josh Support X-Http-Method-Override header in MethodOverride middleware
josh authored
5 METHOD_OVERRIDE_PARAM_KEY = "_method".freeze
6 HTTP_METHOD_OVERRIDE_HEADER = "HTTP_X_HTTP_METHOD_OVERRIDE".freeze
7
e4ad5c7 @josh Add MethodOverride middleware to allow browsers to fake PUT and DELET…
josh authored
8 def initialize(app)
9 @app = app
10 end
11
12 def call(env)
13 if env["REQUEST_METHOD"] == "POST"
14 req = Request.new(env)
8b8690b @josh Support X-Http-Method-Override header in MethodOverride middleware
josh authored
15 method = req.POST[METHOD_OVERRIDE_PARAM_KEY] ||
16 env[HTTP_METHOD_OVERRIDE_HEADER]
17 method = method.to_s.upcase
e4ad5c7 @josh Add MethodOverride middleware to allow browsers to fake PUT and DELET…
josh authored
18 if HTTP_METHODS.include?(method)
e20bf34 @jcrosby Store original HTTP method in MethodOverride middleware
jcrosby authored
19 env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
e4ad5c7 @josh Add MethodOverride middleware to allow browsers to fake PUT and DELET…
josh authored
20 env["REQUEST_METHOD"] = method
21 end
22 end
23
24 @app.call(env)
25 end
26 end
27 end
Something went wrong with that request. Please try again.