http-form_data 2.0.0.pre1 → 2.0.0.pre2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89b84a117e41ca60f5962948d9ce6b4932497080
4
- data.tar.gz: 93238b392e0c1817768d6f24d9d44cb9368b2c30
3
+ metadata.gz: f49eaa6a2789b48f0e43011a737fa95aad75e511
4
+ data.tar.gz: f0768565855e6777a5ef4206e827759871607e4b
5
5
  SHA512:
6
- metadata.gz: 70d163f00ea75806e0268fed63956f554f706ce869bf22bffb13e1aa8f728f7b69b73e8a1ede97bf05efbbd85a62609d1ee4df7eddb81120b95e3f8f88731d36
7
- data.tar.gz: be03a767b75746a513e78a56ac7dace8da976da47b35b5a3ba15c149c2807e4d2c8a3a06d107e09cd566703d34471cde4b47316a636f6ffd2fe8ce8a18357936
6
+ metadata.gz: c44060c6430184df6628fe2972656546744e6434a40446d649851de99e5c7e8be0d5dce0307a6aeff11794fa1b1d77a620d26a085f15fa8316b74aac39e91c2a
7
+ data.tar.gz: ed0d387052a1d0681a4b086fd5354e12f0a1a2776a1b35277611deda95d5f10285223bcd352447ffe4fe47af301b4fe97a91d628ae39702fb6b702411c5b432a
data/CHANGES.md CHANGED
@@ -1,4 +1,11 @@
1
- ## 2.0.0-pre1 (2017-05-10)
1
+ ## 2.0.0.pre2 (2017-05-11)
2
+
3
+ * [#14](https://github.com/httprb/form_data/pull/14)
4
+ Enable streaming for urlencoded form data.
5
+ [@janko-m][]
6
+
7
+
8
+ ## 2.0.0.pre1 (2017-05-10)
2
9
 
3
10
  * [#12](https://github.com/httprb/form_data.rb/pull/12)
4
11
  Enable form data streaming.
@@ -1,21 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "http/form_data/readable"
4
+
3
5
  require "uri"
6
+ require "stringio"
4
7
 
5
8
  module HTTP
6
9
  module FormData
7
10
  # `application/x-www-form-urlencoded` form data.
8
11
  class Urlencoded
12
+ include Readable
13
+
9
14
  # @param [#to_h, Hash] data form data key-value Hash
10
15
  def initialize(data)
11
- @data = FormData.ensure_hash data
12
- end
13
-
14
- # Returns content to be used for HTTP request body.
15
- #
16
- # @return [String]
17
- def to_s
18
- ::URI.encode_www_form @data
16
+ uri_encoded_data = ::URI.encode_www_form FormData.ensure_hash(data)
17
+ @io = StringIO.new(uri_encoded_data)
19
18
  end
20
19
 
21
20
  # Returns MIME type to be used for HTTP request `Content-Type` header.
@@ -29,9 +28,7 @@ module HTTP
29
28
  # `Content-Length` header.
30
29
  #
31
30
  # @return [Integer]
32
- def content_length
33
- to_s.bytesize
34
- end
31
+ alias content_length size
35
32
  end
36
33
  end
37
34
  end
@@ -3,6 +3,6 @@
3
3
  module HTTP
4
4
  module FormData
5
5
  # Gem version.
6
- VERSION = "2.0.0.pre1"
6
+ VERSION = "2.0.0.pre2"
7
7
  end
8
8
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe HTTP::FormData::Multipart do
4
+ subject(:form_data) { HTTP::FormData::Multipart.new params }
5
+
4
6
  let(:file) { HTTP::FormData::File.new fixture "the-http-gem.info" }
5
7
  let(:params) { { :foo => :bar, :baz => file } }
6
8
  let(:boundary) { /-{21}[a-f0-9]{42}/ }
7
- subject(:form_data) { HTTP::FormData::Multipart.new params }
8
9
 
9
10
  describe "#to_s" do
10
11
  def disposition(params)
@@ -15,7 +16,7 @@ RSpec.describe HTTP::FormData::Multipart do
15
16
  let(:crlf) { "\r\n" }
16
17
 
17
18
  it "properly generates multipart data" do
18
- boundary_value = form_data.content_type[/(#{boundary})$/, 1]
19
+ boundary_value = form_data.boundary
19
20
 
20
21
  expect(form_data.to_s).to eq [
21
22
  "--#{boundary_value}#{crlf}",
@@ -30,7 +31,9 @@ RSpec.describe HTTP::FormData::Multipart do
30
31
  end
31
32
 
32
33
  context "with user-defined boundary" do
33
- let(:form_data) { HTTP::FormData::Multipart.new params, boundary: "my-boundary" }
34
+ subject(:form_data) do
35
+ HTTP::FormData::Multipart.new params, :boundary => "my-boundary"
36
+ end
34
37
 
35
38
  it "uses the given boundary" do
36
39
  expect(form_data.to_s).to eq [
@@ -108,10 +111,13 @@ RSpec.describe HTTP::FormData::Multipart do
108
111
  it { is_expected.to match(content_type) }
109
112
 
110
113
  context "with user-defined boundary" do
111
- let(:form_data) { HTTP::FormData::Multipart.new params, boundary: "my-boundary" }
114
+ let(:form_data) do
115
+ HTTP::FormData::Multipart.new params, :boundary => "my-boundary"
116
+ end
112
117
 
113
118
  it "includes the given boundary" do
114
- expect(form_data.content_type).to eq "multipart/form-data; boundary=my-boundary"
119
+ expect(form_data.content_type)
120
+ .to eq "multipart/form-data; boundary=my-boundary"
115
121
  end
116
122
  end
117
123
  end
@@ -127,7 +133,9 @@ RSpec.describe HTTP::FormData::Multipart do
127
133
  end
128
134
 
129
135
  context "with user-defined boundary" do
130
- let(:form_data) { HTTP::FormData::Multipart.new params, boundary: "my-boundary" }
136
+ let(:form_data) do
137
+ HTTP::FormData::Multipart.new params, :boundary => "my-boundary"
138
+ end
131
139
 
132
140
  it "returns the given boundary" do
133
141
  expect(form_data.boundary).to eq "my-boundary"
@@ -29,4 +29,24 @@ RSpec.describe HTTP::FormData::Urlencoded do
29
29
  it { is_expected.to eq "foo%5Bbar%5D=%D1%82%D0%B5%D1%81%D1%82" }
30
30
  end
31
31
  end
32
+
33
+ describe "#size" do
34
+ it "returns bytesize of multipart data" do
35
+ expect(form_data.size).to eq form_data.to_s.bytesize
36
+ end
37
+ end
38
+
39
+ describe "#read" do
40
+ it "returns multipart data" do
41
+ expect(form_data.read).to eq form_data.to_s
42
+ end
43
+ end
44
+
45
+ describe "#rewind" do
46
+ it "rewinds the multipart data IO" do
47
+ form_data.read
48
+ form_data.rewind
49
+ expect(form_data.read).to eq form_data.to_s
50
+ end
51
+ end
32
52
  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.0.0.pre1
4
+ version: 2.0.0.pre2
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: 2017-05-10 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,7 +87,7 @@ rubyforge_project:
87
87
  rubygems_version: 2.6.11
88
88
  signing_key:
89
89
  specification_version: 4
90
- summary: http-form_data-2.0.0.pre1
90
+ summary: http-form_data-2.0.0.pre2
91
91
  test_files:
92
92
  - spec/fixtures/expected-multipart-body.tpl
93
93
  - spec/fixtures/the-http-gem.info