actionpack-xml_parser 1.0.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 +7 -0
- data/LICENSE +22 -0
- data/README.md +20 -0
- data/lib/action_dispatch/xml_params_parser.rb +50 -0
- data/lib/actionpack/xml_parser.rb +1 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a4811a13f95b2fa6d83a8b28b7d5e86e4e7f2984
|
4
|
+
data.tar.gz: 7c8be5d2faf72b0bcd7fca1e13ee3167176aa3d6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93007bf9192e7d5515cf3612694aede4178f00aa61a35579408b346590f269f93f3a3c420fdcb94aff759568af5eb537ca8c55dd07f2821fa3ae966e96615abf
|
7
|
+
data.tar.gz: ee82c2862b67fdab4cd4c5a2dd5b82d7d8ffcee60cb92fbe88646058e7d861759a5f27619789ce0057c89ae2e78906011cd8d0fdf3610083dfeb800e9d7d788f
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Prem Sichanugrist
|
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,20 @@
|
|
1
|
+
actionpack-xml\_parser
|
2
|
+
======================
|
3
|
+
|
4
|
+
A XML parameters parser for Action Pack (removed from core in Rails 4.0)
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Include this gem into your Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'actionpack-xml_parser'
|
13
|
+
```
|
14
|
+
|
15
|
+
Then, add `ActionDispatch::XmlParamsParser` middleware after `ActionDispatch::ParamsParser`
|
16
|
+
in `config/application.rb`:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
config.middleware.insert_after ActionDispatch::ParamsParser, ActionDispatch::XmlParamsParser
|
20
|
+
```
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'active_support/core_ext/hash/conversions'
|
2
|
+
require 'action_dispatch/http/request'
|
3
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
4
|
+
|
5
|
+
module ActionDispatch
|
6
|
+
class XmlParamsParser
|
7
|
+
def initialize(app)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
if params = parse_formatted_parameters(env)
|
13
|
+
env["action_dispatch.request.request_parameters"] = params
|
14
|
+
end
|
15
|
+
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def parse_formatted_parameters(env)
|
21
|
+
request = Request.new(env)
|
22
|
+
|
23
|
+
return false if request.content_length.zero?
|
24
|
+
|
25
|
+
mime_type = content_type_from_legacy_post_data_format_header(env) ||
|
26
|
+
request.content_mime_type
|
27
|
+
|
28
|
+
if mime_type == Mime::XML
|
29
|
+
data = request.deep_munge(Hash.from_xml(request.body.read) || {})
|
30
|
+
data.with_indifferent_access
|
31
|
+
else
|
32
|
+
false
|
33
|
+
end
|
34
|
+
rescue Exception => e # XML code block errors
|
35
|
+
logger(env).debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}"
|
36
|
+
|
37
|
+
raise ActionDispatch::ParamsParser::ParseError.new(e.message, e)
|
38
|
+
end
|
39
|
+
|
40
|
+
def content_type_from_legacy_post_data_format_header(env)
|
41
|
+
if env['HTTP_X_POST_DATA_FORMAT'].to_s.downcase == 'xml'
|
42
|
+
Mime::XML
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def logger(env)
|
47
|
+
env['action_dispatch.logger'] || ActiveSupport::Logger.new($stderr)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'action_dispatch/xml_params_parser'
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionpack-xml_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Prem Sichanugrist
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0.rc1
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.0.0.rc1
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description:
|
48
|
+
email: s@sikac.hu
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.md
|
53
|
+
files:
|
54
|
+
- LICENSE
|
55
|
+
- README.md
|
56
|
+
- lib/action_dispatch/xml_params_parser.rb
|
57
|
+
- lib/actionpack/xml_parser.rb
|
58
|
+
homepage: http://www.rubyonrails.org
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --main
|
65
|
+
- README.md
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 1.9.3
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.0.3
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: XML parameters parser for Action Pack (removed from core in Rails 4.0)
|
84
|
+
test_files: []
|