rack-parser 0.5.0 → 0.6.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.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/rack/parser.rb +1 -1
- data/rack-parser.gemspec +1 -1
- data/spec/parser_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a7ddcfcf164a59f2e0a35d8dbc197e742c715db
|
4
|
+
data.tar.gz: cb8b0b947daa30f8ef17276d1d2f81a16897b907
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b19155797c75b417c940feb83f10ff6384833215db9b010415e674aad87894f992d49aeb5440b45d4b03fc644493ee2a280f5825f7e2783f862228b94b2fff23
|
7
|
+
data.tar.gz: 8ad8459f09be43fc97dbd1b5baf382da16a2e1e94745bf011b5d258b1cf36dad111a5235ba81b2d20926826214e05b9e86489314bb907ccd0904c6aaa7fb9ba1
|
data/README.md
CHANGED
@@ -67,6 +67,9 @@ override the default response as well.
|
|
67
67
|
|
68
68
|
If no content_type error handling response is present, it will return `400`
|
69
69
|
|
70
|
+
Do note, the error handler rescues exceptions that are descents of `StandardError`. See
|
71
|
+
http://www.mikeperham.com/2012/03/03/the-perils-of-rescue-exception/
|
72
|
+
|
70
73
|
### Regex Matching ###
|
71
74
|
|
72
75
|
With version `0.4.0`, you can specify regex matches for the content
|
@@ -99,7 +102,7 @@ This project came to being because of:
|
|
99
102
|
* [Moonsik Kang](https://github.com/deepblue) - skip rack parser for content types that are not explicitly set.
|
100
103
|
* [Guillermo Iguaran](https://github.com/guilleiguaran) - Updating `multi_xml` version dependency for XML/YAML exploit
|
101
104
|
* [Doug Orleans](https://github.com/dougo) - Handle only post-body parsing errors and let upstream errors propogate downstream
|
102
|
-
* [Akshay Moghe](https://github.com/amoghe) - Make default error handler rack compliant by responding to #each
|
105
|
+
* [Akshay Moghe](https://github.com/amoghe) - Make default error handler rack compliant by responding to #each and use StandardError
|
103
106
|
|
104
107
|
## Copyright
|
105
108
|
|
data/lib/rack/parser.rb
CHANGED
@@ -30,7 +30,7 @@ module Rack
|
|
30
30
|
begin
|
31
31
|
parsed = parser.last.call body
|
32
32
|
env.update FORM_HASH => parsed, FORM_INPUT => env[POST_BODY]
|
33
|
-
rescue
|
33
|
+
rescue StandardError => e
|
34
34
|
warn! e, type
|
35
35
|
handler = handlers.detect { |content_type, _| type.match(content_type) }
|
36
36
|
handler ||= ['default', ERROR_HANDLER]
|
data/rack-parser.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "rack-parser"
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.6.0"
|
7
7
|
s.authors = ["Arthur Chiu"]
|
8
8
|
s.email = ["mr.arthur.chiu@gmail.com"]
|
9
9
|
s.homepage = "https://www.github.com/achiu/rack-parser"
|
data/spec/parser_spec.rb
CHANGED
@@ -43,7 +43,7 @@ describe Rack::Parser do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it "handles upstream errors" do
|
46
|
-
assert_raises
|
46
|
+
assert_raises StandardError, 'error!' do
|
47
47
|
parser = proc { |data| JSON.parse data }
|
48
48
|
stack Rack::Parser, :parsers => { %r{json} => parser }
|
49
49
|
post '/error', '{}', { 'CONTENT_TYPE' => 'application/json' }
|
@@ -51,7 +51,7 @@ describe Rack::Parser do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "returns a default error" do
|
54
|
-
parser = proc { |data| raise
|
54
|
+
parser = proc { |data| raise StandardError, 'wah wah' }
|
55
55
|
stack Rack::Parser, :parsers => { %r{json} => parser }
|
56
56
|
post '/post', '{}', { 'CONTENT_TYPE' => 'application/vnd.foo+json' }
|
57
57
|
|
@@ -59,7 +59,7 @@ describe Rack::Parser do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it "returns a custom error message" do
|
62
|
-
parser = proc { |data| raise
|
62
|
+
parser = proc { |data| raise StandardError, "wah wah" }
|
63
63
|
handler = proc { |err, type| [500, {}, "%s : %s" % [type, err]] }
|
64
64
|
stack Rack::Parser, :parsers => { %r{json} => parser },
|
65
65
|
:handlers => { %r{json} => handler }
|
data/spec/spec_helper.rb
CHANGED
@@ -14,7 +14,7 @@ class ParserApp
|
|
14
14
|
case request.path
|
15
15
|
when '/' then [200, 'Hello World']
|
16
16
|
when '/post' then [200, request.params.inspect]
|
17
|
-
when '/error' then raise(
|
17
|
+
when '/error' then raise(StandardError, 'error!')
|
18
18
|
else
|
19
19
|
[404, 'Nothing']
|
20
20
|
end
|