rack-fake-method 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +15 -0
- data/Rakefile +10 -0
- data/lib/rack/fake_method.rb +7 -0
- data/lib/rack/fake_method/middleware.rb +28 -0
- data/lib/rack/fake_method/version.rb +5 -0
- data/rack-fake-method.gemspec +24 -0
- data/spec/middleware_spec.rb +41 -0
- data/spec/spec_helper.rb +5 -0
- metadata +109 -0
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Thorben Schröder
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Rack::Fake::Method
|
2
|
+
|
3
|
+
Flash does not support any other messages than ``GET`` and ``POST`` with it's ``URLLoader`` class. This middleware allows any application to accept an incoming ``POST`` request to act as a request with a different HTTP method. Just set the ``FAKE-METHOD`` HTTP header to anything you want and the middleware will use that as your HTTP method.
|
4
|
+
|
5
|
+
In order to work properly make sure to include the middleware as early as possible in your applications middleware chain.
|
6
|
+
|
7
|
+
## Example
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'rack/fake_method'
|
11
|
+
|
12
|
+
use Rack::FakeMethod::Middleware
|
13
|
+
use SomeOtherMiddleware
|
14
|
+
run YourApp
|
15
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Rack
|
2
|
+
module FakeMethod
|
3
|
+
class Middleware
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
switch_method_to!(env, fake_method(env)) if post?(env) && fake_method(env)
|
10
|
+
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
def post?(env)
|
16
|
+
env['REQUEST_METHOD'] == 'POST'
|
17
|
+
end
|
18
|
+
|
19
|
+
def fake_method(env)
|
20
|
+
env['HTTP_FAKE_METHOD']
|
21
|
+
end
|
22
|
+
|
23
|
+
def switch_method_to!(env, method)
|
24
|
+
env['REQUEST_METHOD'] = method
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/fake_method/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-fake-method"
|
8
|
+
spec.version = Rack::FakeMethod::VERSION
|
9
|
+
spec.authors = ["Thorben Schröder"]
|
10
|
+
spec.email = ["stillepost@gmail.com"]
|
11
|
+
spec.description = %q{A middleware to fake all HTTP methods types with the ``FAKE-METHOD`` header}
|
12
|
+
spec.summary = %q{A middleware to fake all HTTP methods types with the ``FAKE-METHOD`` header}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rack-client"
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative './spec_helper'
|
2
|
+
|
3
|
+
require 'rack/client'
|
4
|
+
require 'rack/fake_method'
|
5
|
+
|
6
|
+
class FakeApp
|
7
|
+
def call(env)
|
8
|
+
[200, {'Content-Type' => 'text/plain'}, [env['REQUEST_METHOD']]]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
HTTP_METHODS = %w{GET POST PUT DELETE HEAD OPTIONS PATCH}
|
13
|
+
|
14
|
+
describe Rack::FakeMethod do
|
15
|
+
before do
|
16
|
+
@client = Rack::Client.new do
|
17
|
+
use Rack::FakeMethod::Middleware
|
18
|
+
run FakeApp.new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "runs all normal methods just fine" do
|
23
|
+
HTTP_METHODS.each do |method|
|
24
|
+
@client.request(method.downcase, '/').body.must_equal method
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "does not fake the method when the original method is not POST" do
|
29
|
+
HTTP_METHODS.each do |method|
|
30
|
+
next if method == 'POST'
|
31
|
+
@client.request(method.downcase, '/', 'FAKE-METHOD' => 'POST').body.must_equal method
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "fakes the method when the original is POST" do
|
36
|
+
HTTP_METHODS.each do |method|
|
37
|
+
next if method == 'POST'
|
38
|
+
@client.post('/', 'FAKE-METHOD' => method).body.must_equal method
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-fake-method
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thorben Schröder
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rack-client
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: A middleware to fake all HTTP methods types with the ``FAKE-METHOD``
|
63
|
+
header
|
64
|
+
email:
|
65
|
+
- stillepost@gmail.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- CHANGELOG.md
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- lib/rack/fake_method.rb
|
77
|
+
- lib/rack/fake_method/middleware.rb
|
78
|
+
- lib/rack/fake_method/version.rb
|
79
|
+
- rack-fake-method.gemspec
|
80
|
+
- spec/middleware_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
homepage: ''
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.25
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: A middleware to fake all HTTP methods types with the ``FAKE-METHOD`` header
|
107
|
+
test_files:
|
108
|
+
- spec/middleware_spec.rb
|
109
|
+
- spec/spec_helper.rb
|