roda 2.13.0 → 2.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/doc/release_notes/2.14.0.txt +44 -0
- data/lib/roda/plugins/middleware.rb +15 -4
- data/lib/roda/plugins/symbol_status.rb +30 -0
- data/lib/roda/version.rb +1 -1
- data/spec/plugin/middleware_spec.rb +20 -0
- data/spec/plugin/symbol_matchers_spec.rb +5 -0
- data/spec/plugin/symbol_status_spec.rb +23 -0
- data/spec/plugin/websockets_spec.rb +5 -3
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cde8be71334a4d1be45b77656f9314fbac254bd1
|
4
|
+
data.tar.gz: 6c100351e8af6103d141f64967971c3e56dec13d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9084568d409627ac84c60d16049a6d2c545bdd9ac6cd6ba4dc312720474ccebc4e859dcc559d7e82390b66e04f31b06ee63ba32a288df57a832ea36ed18fd2ef
|
7
|
+
data.tar.gz: 74b8305898e306b49179ccb05349d4cf25a8fd4f7d481baec071728626a6c1eec99f40fd04faa6d85321e256154db6bf9a74717dbee50a50edad22f552152086
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
= 2.14.0 (2016-05-13)
|
2
|
+
|
3
|
+
* Add symbol_status plugin for using symbols as status codes (Papierkorb) (#65)
|
4
|
+
|
5
|
+
* Make middleware plugin also run the application's middleware (jeremyevans)
|
6
|
+
|
1
7
|
= 2.13.0 (2016-04-14)
|
2
8
|
|
3
9
|
* Add :check_paths and :allowed_paths to render plugin options to avoid security issues with template rendering (jeremyevans)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* A symbol_status plugin has been added for using symbolic status names
|
4
|
+
in response.status=:
|
5
|
+
|
6
|
+
class App < Roda
|
7
|
+
plugin :symbol_status
|
8
|
+
|
9
|
+
route do |r|
|
10
|
+
r.is "needs_authorization"
|
11
|
+
response.status = :unauthorized
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
= Other Improvements
|
16
|
+
|
17
|
+
* The middleware plugin will now also run the application's middleware
|
18
|
+
when the application is used as middleware. For example, if you
|
19
|
+
have the following code in your config.ru file:
|
20
|
+
|
21
|
+
class App < Roda
|
22
|
+
plugin :csrf
|
23
|
+
plugin :middleware
|
24
|
+
route{}
|
25
|
+
end
|
26
|
+
|
27
|
+
use App
|
28
|
+
|
29
|
+
previously, the csrf protection would not be enforced, as it uses a
|
30
|
+
middleware instead of being part of the application. Now, csrf
|
31
|
+
protection will be enforced. This change makes it so the Roda
|
32
|
+
application operates the same way regardless of whether it is run
|
33
|
+
as the rack application or used as rack middleware.
|
34
|
+
|
35
|
+
Because of this change, if you are nesting roda applications using
|
36
|
+
the middleware plugin, you may need to use the middleware plugin's
|
37
|
+
:env_var option to specify the environment variable used to
|
38
|
+
indicate to the Roda application that it is being run as middleware.
|
39
|
+
|
40
|
+
= Backwards Compatibility
|
41
|
+
|
42
|
+
* See above changes to the middleware plugin if you are using
|
43
|
+
middleware inside a Roda application that uses the middleware
|
44
|
+
plugin.
|
@@ -36,6 +36,16 @@ class Roda
|
|
36
36
|
# It is possible to use the Roda app as a regular app even when using
|
37
37
|
# the middleware plugin.
|
38
38
|
module Middleware
|
39
|
+
# Configure the middleware plugin. Options:
|
40
|
+
# :env_var :: Set the environment variable to use to indicate to the roda
|
41
|
+
# application that the current request is a middleware request.
|
42
|
+
# You should only need to override this if you are using multiple
|
43
|
+
# roda middleware in the same application.
|
44
|
+
def self.configure(app, opts={})
|
45
|
+
app.opts[:middleware_env_var] = opts[:env_var] if opts.has_key?(:env_var)
|
46
|
+
app.opts[:middleware_env_var] ||= 'roda.forward_next'
|
47
|
+
end
|
48
|
+
|
39
49
|
# Forward instances are what is actually used as middleware.
|
40
50
|
class Forwarder
|
41
51
|
# Store the current middleware and the next middleware to call.
|
@@ -51,9 +61,8 @@ class Roda
|
|
51
61
|
res = nil
|
52
62
|
|
53
63
|
call_next = catch(:next) do
|
54
|
-
|
55
|
-
|
56
|
-
res = scope.call(&@mid.route_block)
|
64
|
+
env[@mid.opts[:middleware_env_var]] = true
|
65
|
+
res = @mid.call(env)
|
57
66
|
false
|
58
67
|
end
|
59
68
|
|
@@ -89,7 +98,9 @@ class Roda
|
|
89
98
|
module RequestMethods
|
90
99
|
# Whether to forward the request to the next application. Set only if
|
91
100
|
# this request is being performed for middleware.
|
92
|
-
|
101
|
+
def forward_next
|
102
|
+
env[roda_class.opts[:middleware_env_var]]
|
103
|
+
end
|
93
104
|
end
|
94
105
|
end
|
95
106
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
class Roda
|
4
|
+
module RodaPlugins
|
5
|
+
# The symbol_status plugin patches the +status=+ response method to
|
6
|
+
# accept the status name as a symbol. If given an integer value,
|
7
|
+
# the default behaviour is used.
|
8
|
+
#
|
9
|
+
# Examples:
|
10
|
+
# r.is "needs_authorization"
|
11
|
+
# response.status = :unauthorized
|
12
|
+
# end
|
13
|
+
# r.is "nothing"
|
14
|
+
# response.status = :no_content
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# The conversion is done through <tt>Rack::Utils.status_code</tt>.
|
18
|
+
module SymbolStatus
|
19
|
+
module ResponseMethods
|
20
|
+
# Sets the response status code by fixnum or symbol name
|
21
|
+
def status=(code)
|
22
|
+
code = Rack::Utils.status_code(code) if code.is_a?(Symbol)
|
23
|
+
super(code)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
register_plugin(:symbol_status, SymbolStatus)
|
29
|
+
end
|
30
|
+
end
|
data/lib/roda/version.rb
CHANGED
@@ -75,4 +75,24 @@ describe "middleware plugin" do
|
|
75
75
|
|
76
76
|
body('/a/b').must_equal 'ab'
|
77
77
|
end
|
78
|
+
|
79
|
+
it "uses the app's middleware if :include_middleware option is given" do
|
80
|
+
mid = Struct.new(:app) do
|
81
|
+
def call(env)
|
82
|
+
env['foo'] = 'bar'
|
83
|
+
app.call(env)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
app(:bare) do
|
87
|
+
plugin :middleware, :include_middleware=>true
|
88
|
+
use mid
|
89
|
+
route{}
|
90
|
+
end
|
91
|
+
mid2 = app
|
92
|
+
app(:bare) do
|
93
|
+
use mid2
|
94
|
+
route{env['foo']}
|
95
|
+
end
|
96
|
+
body.must_equal 'bar'
|
97
|
+
end
|
78
98
|
end
|
@@ -27,6 +27,10 @@ describe "symbol_matchers plugin" do
|
|
27
27
|
"thing#{d}"
|
28
28
|
end
|
29
29
|
|
30
|
+
r.is "thing2", :thing do |d|
|
31
|
+
"thing2#{d}"
|
32
|
+
end
|
33
|
+
|
30
34
|
r.is :f do |f|
|
31
35
|
"f#{f}"
|
32
36
|
end
|
@@ -69,5 +73,6 @@ describe "symbol_matchers plugin" do
|
|
69
73
|
body("/qa/b/c/d//f/g").must_equal 'resta/b/c/d//f/g'
|
70
74
|
body('/q').must_equal 'rest'
|
71
75
|
body('/thing/q').must_equal 'thingq'
|
76
|
+
body('/thing2/q').must_equal 'thing2q'
|
72
77
|
end
|
73
78
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
|
2
|
+
|
3
|
+
describe "symbol_status plugin" do
|
4
|
+
it "accepts a symbol" do
|
5
|
+
app(:symbol_status) do |r|
|
6
|
+
r.on do
|
7
|
+
response.status = :unauthorized
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
status.must_equal 401
|
12
|
+
end
|
13
|
+
|
14
|
+
it "accepts a fixnum" do
|
15
|
+
app(:symbol_status) do |r|
|
16
|
+
r.on do
|
17
|
+
response.status = 204
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
status.must_equal 204
|
22
|
+
end
|
23
|
+
end
|
@@ -61,21 +61,23 @@ describe "websockets plugin" do
|
|
61
61
|
it "supports websocket requests" do
|
62
62
|
ws = Faye::WebSocket::Client.new("ws://localhost:#{@port}")
|
63
63
|
msg = nil
|
64
|
+
sleep_for = 0.01
|
65
|
+
wait_for = 10
|
64
66
|
ws.on(:open){|event| msg = true}
|
65
67
|
t = Time.now
|
66
|
-
sleep
|
68
|
+
sleep sleep_for until msg || Time.now - t > wait_for
|
67
69
|
msg.must_equal true
|
68
70
|
|
69
71
|
msg = nil
|
70
72
|
ws.on(:message){|event| msg = event.data}
|
71
73
|
ws.send("hello")
|
72
74
|
t = Time.now
|
73
|
-
sleep
|
75
|
+
sleep sleep_for until msg || Time.now - t > wait_for
|
74
76
|
msg.must_equal 'olleh'
|
75
77
|
|
76
78
|
ws.close
|
77
79
|
t = Time.now
|
78
|
-
sleep
|
80
|
+
sleep sleep_for until @events == %w'open hello close' || Time.now - t > wait_for
|
79
81
|
@events.must_equal %w'open hello close'
|
80
82
|
end
|
81
83
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -179,6 +179,7 @@ extra_rdoc_files:
|
|
179
179
|
- doc/release_notes/2.11.0.txt
|
180
180
|
- doc/release_notes/2.12.0.txt
|
181
181
|
- doc/release_notes/2.13.0.txt
|
182
|
+
- doc/release_notes/2.14.0.txt
|
182
183
|
files:
|
183
184
|
- CHANGELOG
|
184
185
|
- MIT-LICENSE
|
@@ -195,6 +196,7 @@ files:
|
|
195
196
|
- doc/release_notes/2.11.0.txt
|
196
197
|
- doc/release_notes/2.12.0.txt
|
197
198
|
- doc/release_notes/2.13.0.txt
|
199
|
+
- doc/release_notes/2.14.0.txt
|
198
200
|
- doc/release_notes/2.2.0.txt
|
199
201
|
- doc/release_notes/2.3.0.txt
|
200
202
|
- doc/release_notes/2.4.0.txt
|
@@ -269,6 +271,7 @@ files:
|
|
269
271
|
- lib/roda/plugins/status_handler.rb
|
270
272
|
- lib/roda/plugins/streaming.rb
|
271
273
|
- lib/roda/plugins/symbol_matchers.rb
|
274
|
+
- lib/roda/plugins/symbol_status.rb
|
272
275
|
- lib/roda/plugins/symbol_views.rb
|
273
276
|
- lib/roda/plugins/view_options.rb
|
274
277
|
- lib/roda/plugins/view_subdirs.rb
|
@@ -347,6 +350,7 @@ files:
|
|
347
350
|
- spec/plugin/status_handler_spec.rb
|
348
351
|
- spec/plugin/streaming_spec.rb
|
349
352
|
- spec/plugin/symbol_matchers_spec.rb
|
353
|
+
- spec/plugin/symbol_status_spec.rb
|
350
354
|
- spec/plugin/symbol_views_spec.rb
|
351
355
|
- spec/plugin/view_options_spec.rb
|
352
356
|
- spec/plugin/websockets_spec.rb
|