multipart-post 2.0.0 → 2.1.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/.rspec +5 -0
- data/.travis.yml +17 -6
- data/.yardopts +6 -0
- data/Gemfile +0 -8
- data/History.txt +5 -1
- data/LICENSE +21 -0
- data/README.md +111 -61
- data/lib/composite_io.rb +10 -10
- data/lib/multipart_post.rb +1 -1
- data/lib/multipartable.rb +40 -21
- data/lib/net/http/post/multipart.rb +4 -3
- data/lib/parts.rb +38 -8
- data/multipart-post.gemspec +18 -17
- data/spec/composite_io_spec.rb +138 -0
- data/{test → spec}/multibyte.txt +0 -0
- data/{test/net/http/post/test_multipart.rb → spec/net/http/post/multipart_spec.rb} +66 -53
- data/spec/parts_spec.rb +102 -0
- data/spec/spec_helper.rb +29 -0
- metadata +75 -34
- data/test/test_composite_io.rb +0 -115
- data/test/test_parts.rb +0 -86
metadata
CHANGED
@@ -1,28 +1,80 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multipart-post
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nick Sieger
|
8
|
+
- Samuel Williams
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
|
12
|
+
date: 2019-05-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '3'
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.3'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.4'
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: 'Use with Net::HTTP to do multipart form postspec. IO values that have
|
15
63
|
#content_type, #original_filename, and #local_path will be posted as a binary file.'
|
16
64
|
email:
|
17
65
|
- nick@nicksieger.com
|
66
|
+
- samuel.williams@oriontransfer.co.nz
|
18
67
|
executables: []
|
19
68
|
extensions: []
|
20
69
|
extra_rdoc_files: []
|
21
70
|
files:
|
22
|
-
- .gitignore
|
23
|
-
- .
|
71
|
+
- ".gitignore"
|
72
|
+
- ".rspec"
|
73
|
+
- ".travis.yml"
|
74
|
+
- ".yardopts"
|
24
75
|
- Gemfile
|
25
76
|
- History.txt
|
77
|
+
- LICENSE
|
26
78
|
- Manifest.txt
|
27
79
|
- README.md
|
28
80
|
- Rakefile
|
@@ -32,48 +84,37 @@ files:
|
|
32
84
|
- lib/net/http/post/multipart.rb
|
33
85
|
- lib/parts.rb
|
34
86
|
- multipart-post.gemspec
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
87
|
+
- spec/composite_io_spec.rb
|
88
|
+
- spec/multibyte.txt
|
89
|
+
- spec/net/http/post/multipart_spec.rb
|
90
|
+
- spec/parts_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
39
92
|
homepage: https://github.com/nicksieger/multipart-post
|
40
93
|
licenses:
|
41
94
|
- MIT
|
95
|
+
metadata: {}
|
42
96
|
post_install_message:
|
43
|
-
rdoc_options:
|
44
|
-
- --main
|
45
|
-
- README.md
|
46
|
-
- -SHN
|
47
|
-
- -f
|
48
|
-
- darkfish
|
97
|
+
rdoc_options: []
|
49
98
|
require_paths:
|
50
99
|
- lib
|
51
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
101
|
requirements:
|
54
|
-
- -
|
102
|
+
- - ">="
|
55
103
|
- !ruby/object:Gem::Version
|
56
104
|
version: '0'
|
57
|
-
segments:
|
58
|
-
- 0
|
59
|
-
hash: 3851181222699685043
|
60
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
106
|
requirements:
|
63
|
-
- -
|
107
|
+
- - ">="
|
64
108
|
- !ruby/object:Gem::Version
|
65
109
|
version: '0'
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
hash: 3851181222699685043
|
69
110
|
requirements: []
|
70
|
-
|
71
|
-
rubygems_version: 1.8.23
|
111
|
+
rubygems_version: 3.0.2
|
72
112
|
signing_key:
|
73
|
-
specification_version:
|
113
|
+
specification_version: 4
|
74
114
|
summary: A multipart form post accessory for Net::HTTP.
|
75
115
|
test_files:
|
76
|
-
-
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
116
|
+
- spec/composite_io_spec.rb
|
117
|
+
- spec/multibyte.txt
|
118
|
+
- spec/net/http/post/multipart_spec.rb
|
119
|
+
- spec/parts_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
data/test/test_composite_io.rb
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2007-2013 Nick Sieger.
|
3
|
-
# See the file README.txt included with the distribution for
|
4
|
-
# software license details.
|
5
|
-
#++
|
6
|
-
|
7
|
-
require 'composite_io'
|
8
|
-
require 'stringio'
|
9
|
-
require 'test/unit'
|
10
|
-
require 'timeout'
|
11
|
-
|
12
|
-
class CompositeReadIOTest < Test::Unit::TestCase
|
13
|
-
def setup
|
14
|
-
@io = CompositeReadIO.new(CompositeReadIO.new(StringIO.new('the '), StringIO.new('quick ')),
|
15
|
-
StringIO.new('brown '), StringIO.new('fox'))
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_full_read_from_several_ios
|
19
|
-
assert_equal 'the quick brown fox', @io.read
|
20
|
-
end
|
21
|
-
|
22
|
-
unless RUBY_VERSION < '1.9'
|
23
|
-
def test_read_from_multibyte
|
24
|
-
utf8 = File.open(File.dirname(__FILE__)+'/multibyte.txt')
|
25
|
-
binary = StringIO.new("\x86")
|
26
|
-
@io = CompositeReadIO.new(binary,utf8)
|
27
|
-
|
28
|
-
expect = "\x86\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB\n"
|
29
|
-
expect.force_encoding('BINARY') if expect.respond_to?(:force_encoding)
|
30
|
-
assert_equal expect, @io.read
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_partial_read
|
35
|
-
assert_equal 'the quick', @io.read(9)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_partial_read_to_boundary
|
39
|
-
assert_equal 'the quick ', @io.read(10)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_read_with_size_larger_than_available
|
43
|
-
assert_equal 'the quick brown fox', @io.read(32)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_read_into_buffer
|
47
|
-
buf = ''
|
48
|
-
@io.read(nil, buf)
|
49
|
-
assert_equal 'the quick brown fox', buf
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_multiple_reads
|
53
|
-
assert_equal 'the ', @io.read(4)
|
54
|
-
assert_equal 'quic', @io.read(4)
|
55
|
-
assert_equal 'k br', @io.read(4)
|
56
|
-
assert_equal 'own ', @io.read(4)
|
57
|
-
assert_equal 'fox', @io.read(4)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_read_after_end
|
61
|
-
@io.read
|
62
|
-
assert_equal "", @io.read
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_read_after_end_with_amount
|
66
|
-
@io.read(32)
|
67
|
-
assert_equal nil, @io.read(32)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_second_full_read_after_rewinding
|
71
|
-
@io.read
|
72
|
-
@io.rewind
|
73
|
-
assert_equal 'the quick brown fox', @io.read
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_convert_error
|
77
|
-
assert_raises(ArgumentError) {
|
78
|
-
UploadIO.convert!('tmp.txt', 'text/plain', 'tmp.txt', 'tmp.txt')
|
79
|
-
}
|
80
|
-
end
|
81
|
-
|
82
|
-
## FIXME excluding on JRuby due to
|
83
|
-
## http://jira.codehaus.org/browse/JRUBY-7109
|
84
|
-
if IO.respond_to?(:copy_stream) && !defined?(JRUBY_VERSION)
|
85
|
-
def test_compatible_with_copy_stream
|
86
|
-
target_io = StringIO.new
|
87
|
-
Timeout.timeout(1) do
|
88
|
-
IO.copy_stream(@io, target_io)
|
89
|
-
end
|
90
|
-
assert_equal "the quick brown fox", target_io.string
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_empty
|
95
|
-
io = CompositeReadIO.new
|
96
|
-
assert_equal "", io.read
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_empty_limited
|
100
|
-
io = CompositeReadIO.new
|
101
|
-
assert_nil io.read(1)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_empty_parts
|
105
|
-
io = CompositeReadIO.new(StringIO.new, StringIO.new('the '), StringIO.new, StringIO.new('quick'))
|
106
|
-
assert_equal "the", io.read(3)
|
107
|
-
assert_equal " qu", io.read(3)
|
108
|
-
assert_equal "ick", io.read(4)
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_all_empty_parts
|
112
|
-
io = CompositeReadIO.new(StringIO.new, StringIO.new)
|
113
|
-
assert_nil io.read(1)
|
114
|
-
end
|
115
|
-
end
|
data/test/test_parts.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2007-2012 Nick Sieger.
|
3
|
-
# See the file README.txt included with the distribution for
|
4
|
-
# software license details.
|
5
|
-
#++
|
6
|
-
|
7
|
-
require 'test/unit'
|
8
|
-
|
9
|
-
require 'parts'
|
10
|
-
require 'stringio'
|
11
|
-
require 'composite_io'
|
12
|
-
require 'tempfile'
|
13
|
-
|
14
|
-
|
15
|
-
MULTIBYTE = File.dirname(__FILE__)+'/multibyte.txt'
|
16
|
-
TEMP_FILE = "temp.txt"
|
17
|
-
|
18
|
-
module AssertPartLength
|
19
|
-
def assert_part_length(part)
|
20
|
-
bytes = part.to_io.read
|
21
|
-
bytesize = bytes.respond_to?(:bytesize) ? bytes.bytesize : bytes.length
|
22
|
-
assert_equal bytesize, part.length
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class PartTest < Test::Unit::TestCase
|
27
|
-
def setup
|
28
|
-
@string_with_content_type = Class.new(String) do
|
29
|
-
def content_type; 'application/data'; end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_file_with_upload_io
|
34
|
-
assert Parts::Part.file?(UploadIO.new(__FILE__, "text/plain"))
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_file_with_modified_string
|
38
|
-
assert !Parts::Part.file?(@string_with_content_type.new("Hello"))
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_new_with_modified_string
|
42
|
-
assert_kind_of Parts::ParamPart,
|
43
|
-
Parts::Part.new("boundary", "multibyte", @string_with_content_type.new("Hello"))
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class FilePartTest < Test::Unit::TestCase
|
48
|
-
include AssertPartLength
|
49
|
-
|
50
|
-
def setup
|
51
|
-
File.open(TEMP_FILE, "w") {|f| f << "1234567890"}
|
52
|
-
io = UploadIO.new(TEMP_FILE, "text/plain")
|
53
|
-
@part = Parts::FilePart.new("boundary", "afile", io)
|
54
|
-
end
|
55
|
-
|
56
|
-
def teardown
|
57
|
-
File.delete(TEMP_FILE) rescue nil
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_correct_length
|
61
|
-
assert_part_length @part
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_multibyte_file_length
|
65
|
-
assert_part_length Parts::FilePart.new("boundary", "multibyte", UploadIO.new(MULTIBYTE, "text/plain"))
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_multibyte_filename
|
69
|
-
name = File.read(MULTIBYTE, 300)
|
70
|
-
file = Tempfile.new(name.respond_to?(:force_encoding) ? name.force_encoding("UTF-8") : name)
|
71
|
-
assert_part_length Parts::FilePart.new("boundary", "multibyte", UploadIO.new(file, "text/plain"))
|
72
|
-
file.close
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
class ParamPartTest < Test::Unit::TestCase
|
77
|
-
include AssertPartLength
|
78
|
-
|
79
|
-
def setup
|
80
|
-
@part = Parts::ParamPart.new("boundary", "multibyte", File.read(MULTIBYTE))
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_correct_length
|
84
|
-
assert_part_length @part
|
85
|
-
end
|
86
|
-
end
|