http-form_data 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES.md +9 -1
- data/lib/http/form_data/urlencoded.rb +52 -2
- data/lib/http/form_data/version.rb +1 -1
- data/spec/lib/http/form_data/urlencoded_spec.rb +9 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 91e7ff4611e0a772489c8106a841d5ca29fe86bb
|
4
|
+
data.tar.gz: 2ccf8a6814414a191f016462568ccec8d230b956
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31bcdd5a50c1a3941723999b26037c2d6eceb19f6878ac11e1adecd0fb0ddc12dff07bb01b4267170ade30bbb20889e99fdba458cb443bf137cef329d00ff3c9
|
7
|
+
data.tar.gz: 3a2f82eaab7a8a7cf40e5b0d9e4e33c3c7ba7e0d880787175396142fbb04dac7c9e554fbc7d1bb29b40d3592a8aca569a70d923a7a45cf32febc524f65e7117d
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 2.1.1 (2018-06-01)
|
2
|
+
|
3
|
+
* [#23](https://github.com/httprb/form_data/pull/23)
|
4
|
+
Allow override urlencoded form data encoder.
|
5
|
+
[@FabienChaynes][]
|
6
|
+
|
7
|
+
|
1
8
|
## 2.1.0 (2018-03-05)
|
2
9
|
|
3
10
|
* [#21](https://github.com/httprb/form_data/pull/21)
|
@@ -33,7 +40,7 @@
|
|
33
40
|
## 1.0.2 (2017-05-08)
|
34
41
|
|
35
42
|
* [#5](https://github.com/httprb/form_data.rb/issues/5)
|
36
|
-
Allow setting Content-Type non-file parts
|
43
|
+
Allow setting Content-Type non-file parts
|
37
44
|
[@abotalov][]
|
38
45
|
|
39
46
|
* [#6](https://github.com/httprb/form_data.rb/issues/6)
|
@@ -71,3 +78,4 @@
|
|
71
78
|
[@janko-m]: https://github.com/janko-m
|
72
79
|
[@mhickman]: https://github.com/mhickman
|
73
80
|
[@HoneyryderChuck]: https://github.com/HoneyryderChuck
|
81
|
+
[@FabienChaynes]: https://github.com/FabienChaynes
|
@@ -11,10 +11,60 @@ module HTTP
|
|
11
11
|
class Urlencoded
|
12
12
|
include Readable
|
13
13
|
|
14
|
+
class << self
|
15
|
+
# Set custom form data encoder implementation.
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
#
|
19
|
+
# module CustomFormDataEncoder
|
20
|
+
# UNESCAPED_CHARS = /[^a-z0-9\-\.\_\~]/i
|
21
|
+
#
|
22
|
+
# def self.escape(s)
|
23
|
+
# ::URI::DEFAULT_PARSER.escape(s.to_s, UNESCAPED_CHARS)
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# def self.call(data)
|
27
|
+
# parts = []
|
28
|
+
#
|
29
|
+
# data.each do |k, v|
|
30
|
+
# k = escape(k)
|
31
|
+
#
|
32
|
+
# if v.nil?
|
33
|
+
# parts << k
|
34
|
+
# elsif v.respond_to?(:to_ary)
|
35
|
+
# v.to_ary.each { |vv| parts << "#{k}=#{escape vv}" }
|
36
|
+
# else
|
37
|
+
# parts << "#{k}=#{escape v}"
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# parts.join("&")
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# HTTP::FormData::Urlencoded.encoder = CustomFormDataEncoder
|
46
|
+
#
|
47
|
+
# @raise [ArgumentError] if implementation deos not responds to `#call`.
|
48
|
+
# @param implementation [#call]
|
49
|
+
# @return [void]
|
50
|
+
def encoder=(implementation)
|
51
|
+
raise ArgumentError unless implementation.respond_to? :call
|
52
|
+
@encoder = implementation
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns form data encoder implementation.
|
56
|
+
# Default: `URI.encode_www_form`.
|
57
|
+
#
|
58
|
+
# @see .encoder=
|
59
|
+
# @return [#call]
|
60
|
+
def encoder
|
61
|
+
@encoder ||= ::URI.method(:encode_www_form)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
14
65
|
# @param [#to_h, Hash] data form data key-value Hash
|
15
66
|
def initialize(data)
|
16
|
-
|
17
|
-
@io = StringIO.new(uri_encoded_data)
|
67
|
+
@io = StringIO.new(self.class.encoder.call(FormData.ensure_hash(data)))
|
18
68
|
end
|
19
69
|
|
20
70
|
# Returns MIME type to be used for HTTP request `Content-Type` header.
|
@@ -55,4 +55,13 @@ RSpec.describe HTTP::FormData::Urlencoded do
|
|
55
55
|
expect(form_data.read).to eq form_data.to_s
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
describe ".encoder=" do
|
60
|
+
before { described_class.encoder = ::JSON.method(:dump) }
|
61
|
+
after { described_class.encoder = ::URI.method(:encode_www_form) }
|
62
|
+
|
63
|
+
it "switches form encoder implementation" do
|
64
|
+
expect(form_data.to_s).to eq('{"foo[bar]":"test"}')
|
65
|
+
end
|
66
|
+
end
|
58
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-form_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksey V Zapparov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,10 +84,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
87
|
+
rubygems_version: 2.6.14.1
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
|
-
summary: http-form_data-2.1.
|
90
|
+
summary: http-form_data-2.1.1
|
91
91
|
test_files:
|
92
92
|
- spec/fixtures/expected-multipart-body.tpl
|
93
93
|
- spec/fixtures/the-http-gem.info
|