rack-methodoverride-with-params 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/LICENSE +21 -0
- data/README.md +26 -0
- data/lib/rack-methodoverride-with-params.rb +1 -0
- data/lib/rack/methodoverride-with-params.rb +22 -0
- data/lib/rack/methodoverride-with-params/version.rb +0 -0
- data/rack-methodoverride-with-params.gemspec +17 -0
- data/spec/methodoverride_with_params_spec.rb +38 -0
- metadata +104 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2010 Nick Howard
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Rack MethodOverride With Params
|
2
|
+
===============================
|
3
|
+
Rack MethodOverride With Params solves the issue where POST requests with `_method` as a query param do not use `_method`'s value as the HTTP method in Rails etc that use Rack MethodOverride.
|
4
|
+
|
5
|
+
It does this by extending `Rack::MethodOverride` and overriding it so it looks at both query params and form params. So you can use it anywhere you were using `Rack::MethodOverride`
|
6
|
+
|
7
|
+
To use it with Rack Builder
|
8
|
+
|
9
|
+
require 'rack-methodoverride-with-params'
|
10
|
+
#...
|
11
|
+
use Rack::MethodOverrideWithParams
|
12
|
+
|
13
|
+
to use it with Rails
|
14
|
+
|
15
|
+
add it to the `Gemfile`
|
16
|
+
|
17
|
+
gem 'rack-methodoverride-with-params'
|
18
|
+
|
19
|
+
swap Rack::MethodOverride in `config/environment.rb`
|
20
|
+
|
21
|
+
config.middleware.swap Rack::MethodOverride, Rack::MethodOverrideWithParams
|
22
|
+
Contrib
|
23
|
+
---------------
|
24
|
+
There is not much here, but if you want to play around, clone the project, run the specs and hack away.
|
25
|
+
|
26
|
+
I probably won't be actively working on this much as it is really simple, but if you ping me about it on github or twitter(I'm baroquebobcat), I'll help you out.
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/rack/methodoverride-with-params'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rack'
|
2
|
+
#
|
3
|
+
module Rack
|
4
|
+
class MethodOverrideWithParams < Rack::MethodOverride
|
5
|
+
|
6
|
+
def call(env)
|
7
|
+
if env["REQUEST_METHOD"] == "POST"
|
8
|
+
req = Request.new(env)
|
9
|
+
method = req.params[METHOD_OVERRIDE_PARAM_KEY] ||
|
10
|
+
env[HTTP_METHOD_OVERRIDE_HEADER]
|
11
|
+
method = method.to_s.upcase
|
12
|
+
if HTTP_METHODS.include?(method)
|
13
|
+
env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
|
14
|
+
env["REQUEST_METHOD"] = method
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
@app.call(env)
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "rack-methodoverride-with-params"
|
5
|
+
s.version = "1.0.0"
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.authors = ["Nick Howard"]
|
8
|
+
s.email = ["ndh@baroquebobcat.com"]
|
9
|
+
s.homepage = "http://github.com/baroquebobcat/rack-methodoverride-with-params"
|
10
|
+
s.summary = %q(A replacement for Rack::MethodOverride that looks at query params and post data.)
|
11
|
+
s.description = %q(Rack::MethodOverride only checks the X-Http-Method-Override header and the form encoded post body for _method. Rack::MethodOverrideWithParams checks both of those _and_ the query params. So, if you POST xml with a url like http://example.com/?_method=delete the application will see it as a delete request.)
|
12
|
+
s.required_rubygems_version = ">= 1.3.6"
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.add_dependency "rack", "~> 1"
|
16
|
+
s.add_development_dependency 'rspec', '~> 2'
|
17
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
$:.unshift lib unless $:.include?(lib)
|
3
|
+
|
4
|
+
require 'rack-methodoverride-with-params'
|
5
|
+
|
6
|
+
describe Rack::MethodOverrideWithParams do
|
7
|
+
let(:in_env) { {} }
|
8
|
+
let(:out_env) { subject.call(in_env) }
|
9
|
+
let(:app) {lambda {|env| env}}
|
10
|
+
subject { Rack::MethodOverrideWithParams.new(app)}
|
11
|
+
|
12
|
+
describe "a get request" do
|
13
|
+
it { app.should_receive(:call).with(in_env); out_env }
|
14
|
+
it { out_env.should == in_env }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "a post request" do
|
18
|
+
before {
|
19
|
+
in_env['REQUEST_METHOD']='POST'
|
20
|
+
in_env['rack.input'] = in_env['form_input'] = ''
|
21
|
+
in_env['rack.request.form_input'] = ''
|
22
|
+
in_env["rack.request.form_hash"] = {}
|
23
|
+
}
|
24
|
+
Rack::MethodOverrideWithParams::HTTP_METHODS.each do |method|
|
25
|
+
describe "with _method = #{method} as a post param" do
|
26
|
+
before { in_env["rack.request.form_hash"] = {'_method' => method} }
|
27
|
+
|
28
|
+
it { out_env['REQUEST_METHOD'].should == method }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'with _method = #{method} as a query param' do
|
32
|
+
before { in_env['QUERY_STRING'] = "_method=#{method}" }
|
33
|
+
|
34
|
+
it { out_env['REQUEST_METHOD'].should == method }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-methodoverride-with-params
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nick Howard
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-28 00:00:00 -06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rack
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
version: "1"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 7
|
44
|
+
segments:
|
45
|
+
- 2
|
46
|
+
version: "2"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Rack::MethodOverride only checks the X-Http-Method-Override header and the form encoded post body for _method. Rack::MethodOverrideWithParams checks both of those _and_ the query params. So, if you POST xml with a url like http://example.com/?_method=delete the application will see it as a delete request.
|
50
|
+
email:
|
51
|
+
- ndh@baroquebobcat.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- LICENSE
|
61
|
+
- README.md
|
62
|
+
- lib/rack-methodoverride-with-params.rb
|
63
|
+
- lib/rack/methodoverride-with-params.rb
|
64
|
+
- lib/rack/methodoverride-with-params/version.rb
|
65
|
+
- rack-methodoverride-with-params.gemspec
|
66
|
+
- spec/methodoverride_with_params_spec.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/baroquebobcat/rack-methodoverride-with-params
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 23
|
91
|
+
segments:
|
92
|
+
- 1
|
93
|
+
- 3
|
94
|
+
- 6
|
95
|
+
version: 1.3.6
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.3.7
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: A replacement for Rack::MethodOverride that looks at query params and post data.
|
103
|
+
test_files: []
|
104
|
+
|