rack-parser 0.0.1 → 0.0.3
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/lib/rack/parser.rb +4 -2
- data/rack-parser.gemspec +2 -2
- data/test/parser_test.rb +1 -1
- data/test/teststrap.rb +3 -2
- metadata +2 -2
data/lib/rack/parser.rb
CHANGED
@@ -47,11 +47,13 @@ module Rack
|
|
47
47
|
format = content_type.split('/').last
|
48
48
|
begin
|
49
49
|
result = @content_types[content_type].call(body)
|
50
|
-
env.update FORM_HASH => result, FORM_INPUT =>
|
50
|
+
env.update FORM_HASH => result, FORM_INPUT => env[POST_BODY]
|
51
51
|
@app.call env
|
52
52
|
rescue Exception => e
|
53
53
|
logger.warn "#{self.class} #{content_type} parsing error: #{e.to_s}" if respond_to? :logger # Send to logger if its there.
|
54
|
-
|
54
|
+
meth = "to_#{format}"
|
55
|
+
meth = "inspect" unless Hash.respond_to? meth
|
56
|
+
[400, { 'Content-Type' => content_type }, [ {'errors' => e.to_s}.method(meth).call ] ] # Finally, return an error response.
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
data/rack-parser.gemspec
CHANGED
@@ -3,10 +3,10 @@ $:.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.0.
|
6
|
+
s.version = "0.0.3"
|
7
7
|
s.authors = ["Arthur Chiu"]
|
8
8
|
s.email = ["mr.arthur.chiu@gmail.com"]
|
9
|
-
s.homepage = ""
|
9
|
+
s.homepage = "https://www.github.com/achiu/rack-parser"
|
10
10
|
s.summary = %q{Rack Middleware for parsing post body data}
|
11
11
|
s.description = %q{Rack Middleware for parsing post body data for json/xml and various content types}
|
12
12
|
|
data/test/parser_test.rb
CHANGED
data/test/teststrap.rb
CHANGED
@@ -15,7 +15,8 @@ class Riot::Situation
|
|
15
15
|
return_code, body_text =
|
16
16
|
case request.path
|
17
17
|
when '/' then [200,'Hello world']
|
18
|
-
when '/post'
|
18
|
+
when '/post'
|
19
|
+
[200, Rack::Request.new(env).params]
|
19
20
|
else
|
20
21
|
[404,'Nothing here']
|
21
22
|
end
|
@@ -23,7 +24,7 @@ class Riot::Situation
|
|
23
24
|
}
|
24
25
|
|
25
26
|
builder = Rack::Builder.new
|
26
|
-
builder.use Rack::Parser, :content_types => { 'application/foo' => Proc.new { |b| 'foo' } }
|
27
|
+
builder.use Rack::Parser, :content_types => { 'application/foo' => Proc.new { |b| {'foo' => 'bar'} } }
|
27
28
|
builder.run main_app
|
28
29
|
builder.to_app
|
29
30
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rack-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Arthur Chiu
|
@@ -97,7 +97,7 @@ files:
|
|
97
97
|
- rack-parser.gemspec
|
98
98
|
- test/parser_test.rb
|
99
99
|
- test/teststrap.rb
|
100
|
-
homepage:
|
100
|
+
homepage: https://www.github.com/achiu/rack-parser
|
101
101
|
licenses: []
|
102
102
|
|
103
103
|
post_install_message:
|