rack-parser 0.1.0 → 0.1.1
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/README.md +12 -8
- data/Rakefile +1 -1
- data/lib/rack/parser.rb +2 -2
- data/rack-parser.gemspec +2 -2
- data/test/parser_test.rb +7 -0
- metadata +16 -16
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rack::Parser #
|
2
2
|
|
3
|
-
Rack::Parser is a Rack Middleware for parsing post body data for JSON
|
3
|
+
Rack::Parser is a Rack Middleware for parsing post body data for JSON, XML, and custom
|
4
4
|
content types using MultiJson, MultiXML, or any thing that you want to
|
5
5
|
use.
|
6
6
|
|
@@ -48,13 +48,9 @@ engine of your choice by setting the engine like so:
|
|
48
48
|
# app.rb
|
49
49
|
|
50
50
|
MultiJson.engine = :yajl # Yajl-ruby for json decoding
|
51
|
-
MultiXml.parser
|
51
|
+
MultiXml.parser = :libxml # libxml for XML parsing
|
52
52
|
|
53
|
-
use Rack::Parser
|
54
|
-
'application/json' => Proc.new { |body| MultiJson.decode body },
|
55
|
-
'application/xml' => Proc.new { |body| MultiXml.decode body },
|
56
|
-
'application/roll' => Proc.new { |body| 'never gonna give you up' }
|
57
|
-
}
|
53
|
+
use Rack::Parser
|
58
54
|
```
|
59
55
|
|
60
56
|
To set your own custom engine that perhaps neither MultiJson or MultiXml
|
@@ -63,7 +59,9 @@ support, just make it a Proc:
|
|
63
59
|
|
64
60
|
```ruby
|
65
61
|
use Rack::Parser, :content_types => {
|
66
|
-
'application/json' => Proc.new { |body| MyCustomJsonEngine.do_it body }
|
62
|
+
'application/json' => Proc.new { |body| MyCustomJsonEngine.do_it body },
|
63
|
+
'application/xml' => Proc.new { |body| MyCustomXmlEngine.decode body },
|
64
|
+
'application/roll' => Proc.new { |body| 'never gonna give you up' }
|
67
65
|
}
|
68
66
|
```
|
69
67
|
|
@@ -98,9 +96,15 @@ This project came to being because of:
|
|
98
96
|
* Rack::PostBodyContentTypeParser from rack-contrib which proved to be an inspiration for both libraries.
|
99
97
|
|
100
98
|
|
99
|
+
## External Sources/Documentations
|
100
|
+
|
101
|
+
* [Sinatra book contrib](https://github.com/sinatra/sinatra-book-contrib/blob/master/middleware/rack_parser.md) - mini tutorial on using rack-parser (thanks to [Eric Gjertsen](https://github.com/ericgj))
|
102
|
+
|
103
|
+
|
101
104
|
## Contributors ##
|
102
105
|
|
103
106
|
* [Stephen Becker IV](https://github.com/sbeckeriv) - For initial custom error response handling work.
|
107
|
+
* [Tom May](https://github.com/tommay) - skip loading post body unless content type is set.
|
104
108
|
|
105
109
|
## Copyright
|
106
110
|
|
data/Rakefile
CHANGED
data/lib/rack/parser.rb
CHANGED
@@ -62,9 +62,9 @@ module Rack
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def _call(env)
|
65
|
-
body = env[POST_BODY].read
|
66
|
-
return @app.call(env) if (body.respond_to?(:empty?) ? body.empty? : !body) # Send it down the stack immediately
|
67
65
|
content_type = Rack::Request.new(env).media_type
|
66
|
+
body = env[POST_BODY].read if content_type
|
67
|
+
return @app.call(env) if (body.respond_to?(:empty?) ? body.empty? : !body) # Send it down the stack immediately
|
68
68
|
begin
|
69
69
|
result = @content_types[content_type].call(body)
|
70
70
|
env.update FORM_HASH => result, FORM_INPUT => env[POST_BODY]
|
data/rack-parser.gemspec
CHANGED
@@ -3,12 +3,12 @@ $:.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.1.
|
6
|
+
s.version = "0.1.1"
|
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"
|
10
10
|
s.summary = %q{Rack Middleware for parsing post body data}
|
11
|
-
s.description = %q{Rack Middleware for parsing post body data for json
|
11
|
+
s.description = %q{Rack Middleware for parsing post body data for json, xml and various content types}
|
12
12
|
|
13
13
|
s.rubyforge_project = "rack-parser"
|
14
14
|
|
data/test/parser_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08
|
12
|
+
date: 2011-09-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &2173199560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2173199560
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: multi_json
|
27
|
-
requirement: &
|
27
|
+
requirement: &2173199120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2173199120
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: multi_xml
|
38
|
-
requirement: &
|
38
|
+
requirement: &2173198700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2173198700
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: riot
|
49
|
-
requirement: &
|
49
|
+
requirement: &2173198280 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2173198280
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rack-test
|
60
|
-
requirement: &
|
60
|
+
requirement: &2173197860 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2173197860
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: json
|
71
|
-
requirement: &
|
71
|
+
requirement: &2173197440 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,9 +76,9 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
80
|
-
description: Rack Middleware for parsing post body data for json
|
81
|
-
types
|
79
|
+
version_requirements: *2173197440
|
80
|
+
description: Rack Middleware for parsing post body data for json, xml and various
|
81
|
+
content types
|
82
82
|
email:
|
83
83
|
- mr.arthur.chiu@gmail.com
|
84
84
|
executables: []
|