multipart-post 1.2.0 → 2.2.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
- checksums.yaml.gz.sig +0 -0
- data/lib/composite_io.rb +2 -108
- data/lib/multipart/post/composite_read_io.rb +78 -0
- data/lib/multipart/post/multipartable.rb +75 -0
- data/lib/multipart/post/parts.rb +152 -0
- data/lib/multipart/post/upload_io.rb +81 -0
- data/lib/multipart/post/version.rb +27 -0
- data/lib/multipart/post.rb +24 -0
- data/lib/multipart_post.rb +3 -9
- data/lib/multipartable.rb +2 -20
- data/lib/net/http/post/multipart.rb +29 -15
- data/lib/parts.rb +2 -84
- data.tar.gz.sig +1 -0
- metadata +126 -37
- metadata.gz.sig +2 -0
- data/.gitignore +0 -5
- data/.travis.yml +0 -7
- data/Gemfile +0 -14
- data/Gemfile.lock +0 -39
- data/History.txt +0 -47
- data/Manifest.txt +0 -9
- data/README.txt +0 -62
- data/Rakefile +0 -9
- data/multipart-post.gemspec +0 -21
- data/test/multibyte.txt +0 -1
- data/test/net/http/post/test_multipart.rb +0 -56
- data/test/test_composite_io.rb +0 -115
- data/test/test_parts.rb +0 -57
data/lib/parts.rb
CHANGED
@@ -1,84 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# See the file README.txt included with the distribution for
|
4
|
-
# software license details.
|
5
|
-
#++
|
6
|
-
|
7
|
-
module Parts
|
8
|
-
module Part #:nodoc:
|
9
|
-
def self.new(boundary, name, value)
|
10
|
-
if value.respond_to? :content_type
|
11
|
-
FilePart.new(boundary, name, value)
|
12
|
-
else
|
13
|
-
ParamPart.new(boundary, name, value)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def length
|
18
|
-
@part.length
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_io
|
22
|
-
@io
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class ParamPart
|
27
|
-
include Part
|
28
|
-
def initialize(boundary, name, value)
|
29
|
-
@part = build_part(boundary, name, value)
|
30
|
-
@io = StringIO.new(@part)
|
31
|
-
end
|
32
|
-
|
33
|
-
def length
|
34
|
-
@part.bytesize
|
35
|
-
end
|
36
|
-
|
37
|
-
def build_part(boundary, name, value)
|
38
|
-
part = ''
|
39
|
-
part << "--#{boundary}\r\n"
|
40
|
-
part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\r\n"
|
41
|
-
part << "\r\n"
|
42
|
-
part << "#{value}\r\n"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Represents a part to be filled from file IO.
|
47
|
-
class FilePart
|
48
|
-
include Part
|
49
|
-
attr_reader :length
|
50
|
-
def initialize(boundary, name, io)
|
51
|
-
file_length = io.respond_to?(:length) ? io.length : File.size(io.local_path)
|
52
|
-
@head = build_head(boundary, name, io.original_filename, io.content_type, file_length,
|
53
|
-
io.respond_to?(:opts) ? io.opts : {})
|
54
|
-
@foot = "\r\n"
|
55
|
-
@length = @head.length + file_length + @foot.length
|
56
|
-
@io = CompositeReadIO.new(StringIO.new(@head), io, StringIO.new(@foot))
|
57
|
-
end
|
58
|
-
|
59
|
-
def build_head(boundary, name, filename, type, content_len, opts = {})
|
60
|
-
trans_encoding = opts["Content-Transfer-Encoding"] || "binary"
|
61
|
-
content_disposition = opts["Content-Disposition"] || "form-data"
|
62
|
-
|
63
|
-
part = ''
|
64
|
-
part << "--#{boundary}\r\n"
|
65
|
-
part << "Content-Disposition: #{content_disposition}; name=\"#{name.to_s}\"; filename=\"#{filename}\"\r\n"
|
66
|
-
part << "Content-Length: #{content_len}\r\n"
|
67
|
-
if content_id = opts["Content-ID"]
|
68
|
-
part << "Content-ID: #{content_id}\r\n"
|
69
|
-
end
|
70
|
-
part << "Content-Type: #{type}\r\n"
|
71
|
-
part << "Content-Transfer-Encoding: #{trans_encoding}\r\n"
|
72
|
-
part << "\r\n"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Represents the epilogue or closing boundary.
|
77
|
-
class EpiloguePart
|
78
|
-
include Part
|
79
|
-
def initialize(boundary)
|
80
|
-
@part = "--#{boundary}--\r\n\r\n"
|
81
|
-
@io = StringIO.new(@part)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
1
|
+
warn "Top level ::Parts is deprecated, require 'multipart/post' and use `Multipart::Post::Parts` instead!"
|
2
|
+
require_relative 'multipart/post'
|
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
+�s\�H;�������<4ԏ<�,��X}Ȑv�Z:�'�܋��Љpޡ �?�L��WN"r�� �td‟�q��1�`��?�+e$�l�.�{�]�FwTY#��s��i衦PirD�!�������m��
|
metadata
CHANGED
@@ -1,69 +1,158 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multipart-post
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nick Sieger
|
9
|
-
|
8
|
+
- Samuel Williams
|
9
|
+
- Olle Jonsson
|
10
|
+
- McClain Looney
|
11
|
+
- Lewis Cowles
|
12
|
+
- Gustav Ernberg
|
13
|
+
- Patrick Davey
|
14
|
+
- Steven Davidovitz
|
15
|
+
- Alex Koppel
|
16
|
+
- Ethan Turkeltaub
|
17
|
+
- Jagtesh Chadha
|
18
|
+
- Jason York
|
19
|
+
- Nick
|
20
|
+
- VincWebwag
|
21
|
+
- hasimo
|
22
|
+
- hexfet
|
23
|
+
- Christine Yen
|
24
|
+
- David Moles
|
25
|
+
- Eric Hutzelman
|
26
|
+
- Feuda Nan
|
27
|
+
- Gerrit Riessen
|
28
|
+
- Jan Piotrowski
|
29
|
+
- Jan-Joost Spanjers
|
30
|
+
- Jason Moore
|
31
|
+
- Jeff Hodges
|
32
|
+
- Johannes Wagener
|
33
|
+
- Jordi Massaguer Pla
|
34
|
+
- Lachlan Priest
|
35
|
+
- Leo Cassarani
|
36
|
+
- Lonre Wang
|
37
|
+
- Luke Redpath
|
38
|
+
- Matt Colyer
|
39
|
+
- Mislav Marohnić
|
40
|
+
- Socrates Vicente
|
41
|
+
- Steffen Grunwald
|
42
|
+
- Tim Barkley
|
43
|
+
autorequire:
|
10
44
|
bindir: bin
|
11
|
-
cert_chain:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
45
|
+
cert_chain:
|
46
|
+
- |
|
47
|
+
-----BEGIN CERTIFICATE-----
|
48
|
+
MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
|
49
|
+
ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
|
50
|
+
MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcxNTAzBgNVBAMMLHNhbXVlbC53aWxs
|
51
|
+
aWFtcy9EQz1vcmlvbnRyYW5zZmVyL0RDPWNvL0RDPW56MIIBojANBgkqhkiG9w0B
|
52
|
+
AQEFAAOCAY8AMIIBigKCAYEAyXLSS/cw+fXJ5e7hi+U/TeChPWeYdwJojDsFY1xr
|
53
|
+
xvtqbTTL8gbLHz5LW3QD2nfwCv3qTlw0qI3Ie7a9VMJMbSvgVEGEfQirqIgJXWMj
|
54
|
+
eNMDgKsMJtC7u/43abRKx7TCURW3iWyR19NRngsJJmaR51yGGGm2Kfsr+JtKKLtL
|
55
|
+
L188Wm3f13KAx7QJU8qyuBnj1/gWem076hzdA7xi1DbrZrch9GCRz62xymJlrJHn
|
56
|
+
9iZEZ7AxrS7vokhMlzSr/XMUihx/8aFKtk+tMLClqxZSmBWIErWdicCGTULXCBNb
|
57
|
+
E/mljo4zEVKhlTWpJklMIhr55ZRrSarKFuW7en0+tpJrfsYiAmXMJNi4XAYJH7uL
|
58
|
+
rgJuJwSaa/dMz+VmUoo7VKtSfCoOI+6v5/z0sK3oT6sG6ZwyI47DBq2XqNC6tnAj
|
59
|
+
w+XmCywiTQrFzMMAvcA7rPI4F0nU1rZId51rOvvfxaONp+wgTi4P8owZLw0/j0m4
|
60
|
+
8C20DYi6EYx4AHDXiLpElWh3AgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8E
|
61
|
+
BAMCBLAwHQYDVR0OBBYEFB6ZaeWKxQjGTI+pmz7cKRmMIywwMC4GA1UdEQQnMCWB
|
62
|
+
I3NhbXVlbC53aWxsaWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWB
|
63
|
+
I3NhbXVlbC53aWxsaWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEB
|
64
|
+
CwUAA4IBgQBVoM+pu3dpdUhZM1w051iw5GfiqclAr1Psypf16Tiod/ho//4oAu6T
|
65
|
+
9fj3DPX/acWV9P/FScvqo4Qgv6g4VWO5ZU7z2JmPoTXZtYMunRAmQPFL/gSUc6aK
|
66
|
+
vszMHIyhtyzRc6DnfW2AiVOjMBjaYv8xXZc9bduniRVPrLR4J7ozmGLh4o4uJp7w
|
67
|
+
x9KCFaR8Lvn/r0oJWJOqb/DMAYI83YeN2Dlt3jpwrsmsONrtC5S3gOUle5afSGos
|
68
|
+
bYt5ocnEpKSomR9ZtnCGljds/aeO1Xgpn2r9HHcjwnH346iNrnHmMlC7BtHUFPDg
|
69
|
+
Ts92S47PTOXzwPBDsrFiq3VLbRjHSwf8rpqybQBH9MfzxGGxTaETQYOd6b4e4Ag6
|
70
|
+
y92abGna0bmIEb4+Tx9rQ10Uijh1POzvr/VTH4bbIPy9FbKrRsIQ24qDbNJRtOpE
|
71
|
+
RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
|
72
|
+
HiLJ8VOFx6w=
|
73
|
+
-----END CERTIFICATE-----
|
74
|
+
date: 2022-06-03 00:00:00.000000000 Z
|
75
|
+
dependencies:
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: bundler
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: rake
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: rspec
|
106
|
+
requirement: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.4'
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.4'
|
118
|
+
description:
|
16
119
|
email:
|
17
|
-
- nick@nicksieger.com
|
18
120
|
executables: []
|
19
121
|
extensions: []
|
20
122
|
extra_rdoc_files: []
|
21
123
|
files:
|
22
|
-
- .gitignore
|
23
|
-
- .travis.yml
|
24
|
-
- Gemfile
|
25
|
-
- Gemfile.lock
|
26
|
-
- History.txt
|
27
|
-
- Manifest.txt
|
28
|
-
- README.txt
|
29
|
-
- Rakefile
|
30
124
|
- lib/composite_io.rb
|
125
|
+
- lib/multipart/post.rb
|
126
|
+
- lib/multipart/post/composite_read_io.rb
|
127
|
+
- lib/multipart/post/multipartable.rb
|
128
|
+
- lib/multipart/post/parts.rb
|
129
|
+
- lib/multipart/post/upload_io.rb
|
130
|
+
- lib/multipart/post/version.rb
|
31
131
|
- lib/multipart_post.rb
|
32
132
|
- lib/multipartable.rb
|
33
133
|
- lib/net/http/post/multipart.rb
|
34
134
|
- lib/parts.rb
|
35
|
-
|
36
|
-
- test/multibyte.txt
|
37
|
-
- test/net/http/post/test_multipart.rb
|
38
|
-
- test/test_composite_io.rb
|
39
|
-
- test/test_parts.rb
|
40
|
-
homepage: https://github.com/nicksieger/multipart-post
|
135
|
+
homepage: https://github.com/socketry/multipart-post
|
41
136
|
licenses:
|
42
137
|
- MIT
|
43
|
-
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
44
140
|
rdoc_options: []
|
45
141
|
require_paths:
|
46
142
|
- lib
|
47
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
144
|
requirements:
|
50
|
-
- -
|
145
|
+
- - ">="
|
51
146
|
- !ruby/object:Gem::Version
|
52
147
|
version: '0'
|
53
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
149
|
requirements:
|
56
|
-
- -
|
150
|
+
- - ">="
|
57
151
|
- !ruby/object:Gem::Version
|
58
152
|
version: '0'
|
59
153
|
requirements: []
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
specification_version: 3
|
154
|
+
rubygems_version: 3.3.7
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
64
157
|
summary: A multipart form post accessory for Net::HTTP.
|
65
|
-
test_files:
|
66
|
-
- test/multibyte.txt
|
67
|
-
- test/net/http/post/test_multipart.rb
|
68
|
-
- test/test_composite_io.rb
|
69
|
-
- test/test_parts.rb
|
158
|
+
test_files: []
|
metadata.gz.sig
ADDED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
multipart-post (1.2.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
archive-tar-minitar (0.5.2)
|
10
|
-
columnize (0.3.6)
|
11
|
-
linecache (0.43)
|
12
|
-
linecache19 (0.5.12)
|
13
|
-
ruby_core_source (>= 0.1.4)
|
14
|
-
rake (0.9.2.2)
|
15
|
-
ruby-debug (0.10.3)
|
16
|
-
columnize (>= 0.1)
|
17
|
-
ruby-debug-base (~> 0.10.3.0)
|
18
|
-
ruby-debug-base (0.10.3)
|
19
|
-
linecache (>= 0.3)
|
20
|
-
ruby-debug-base19 (0.11.25)
|
21
|
-
columnize (>= 0.3.1)
|
22
|
-
linecache19 (>= 0.5.11)
|
23
|
-
ruby_core_source (>= 0.1.4)
|
24
|
-
ruby-debug19 (0.11.6)
|
25
|
-
columnize (>= 0.3.1)
|
26
|
-
linecache19 (>= 0.5.11)
|
27
|
-
ruby-debug-base19 (>= 0.11.19)
|
28
|
-
ruby_core_source (0.1.5)
|
29
|
-
archive-tar-minitar (>= 0.5.2)
|
30
|
-
|
31
|
-
PLATFORMS
|
32
|
-
java
|
33
|
-
ruby
|
34
|
-
|
35
|
-
DEPENDENCIES
|
36
|
-
multipart-post!
|
37
|
-
rake
|
38
|
-
ruby-debug
|
39
|
-
ruby-debug19
|
data/History.txt
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
=== 1.2.0 / 2013-02-25
|
2
|
-
|
3
|
-
- #25: Ruby 2 compatibility (thanks mislav)
|
4
|
-
|
5
|
-
=== 1.1.5 / 2012-02-12
|
6
|
-
|
7
|
-
- Fix length/bytesize of parts in 1.9 (#7, #14) (Jason Moore)
|
8
|
-
- Allow CompositeIO objects to be re-read by rewinding, like other IO
|
9
|
-
objects. (Luke Redpath)
|
10
|
-
|
11
|
-
=== 1.1.4 / 2011-11-23
|
12
|
-
|
13
|
-
- Non-functional changes in release (switch to Bundler gem tasks)
|
14
|
-
|
15
|
-
=== 1.1.3 / 2011-07-25
|
16
|
-
|
17
|
-
- More configurable header specification for parts (Gerrit Riessen)
|
18
|
-
|
19
|
-
=== 1.1.2 / 2011-05-24
|
20
|
-
|
21
|
-
- Fix CRLF file part miscalculation (Johannes Wagener)
|
22
|
-
- Fix Epilogue CRLF issue (suggestion by Neil Spring)
|
23
|
-
|
24
|
-
=== 1.1.1 / 2011-05-13
|
25
|
-
|
26
|
-
- GH# 9: Fixed Ruby 1.9.2 StringIO bug (thanks Alex Koppel)
|
27
|
-
|
28
|
-
=== 1.1.0 / 2011-01-11
|
29
|
-
|
30
|
-
- API CHANGE: UploadIO.convert! removed in favor of UploadIO.new
|
31
|
-
(Jeff Hodges)
|
32
|
-
|
33
|
-
=== 1.0.1 / 2010-04-27
|
34
|
-
|
35
|
-
- Doc updates, make gemspec based on more modern Rubygems
|
36
|
-
|
37
|
-
=== 1.0 / 2009-02-12
|
38
|
-
|
39
|
-
- Many fixes from mlooney, seems to work now. Putting the 0.9 seal of
|
40
|
-
approval on it.
|
41
|
-
|
42
|
-
=== 0.1 / 2008-08-12
|
43
|
-
|
44
|
-
* 1 major enhancement
|
45
|
-
|
46
|
-
* Birthday!
|
47
|
-
|
data/Manifest.txt
DELETED
data/README.txt
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
= multipart-post
|
2
|
-
|
3
|
-
* http://github.com/nicksieger/multipart-post
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
Adds a streamy multipart form post capability to Net::HTTP. Also
|
8
|
-
supports other methods besides POST.
|
9
|
-
|
10
|
-
== FEATURES/PROBLEMS:
|
11
|
-
|
12
|
-
* Appears to actually work. A good feature to have.
|
13
|
-
* Encapsulates posting of file/binary parts and name/value parameter parts, similar to
|
14
|
-
most browsers' file upload forms.
|
15
|
-
* Provides an UploadIO helper class to prepare IO objects for inclusion in the params
|
16
|
-
hash of the multipart post object.
|
17
|
-
|
18
|
-
== SYNOPSIS:
|
19
|
-
|
20
|
-
require 'net/http/post/multipart'
|
21
|
-
|
22
|
-
url = URI.parse('http://www.example.com/upload')
|
23
|
-
File.open("./image.jpg") do |jpg|
|
24
|
-
req = Net::HTTP::Post::Multipart.new url.path,
|
25
|
-
"file" => UploadIO.new(jpg, "image/jpeg", "image.jpg")
|
26
|
-
res = Net::HTTP.start(url.host, url.port) do |http|
|
27
|
-
http.request(req)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
== REQUIREMENTS:
|
32
|
-
|
33
|
-
None
|
34
|
-
|
35
|
-
== INSTALL:
|
36
|
-
|
37
|
-
gem install multipart-post
|
38
|
-
|
39
|
-
== LICENSE:
|
40
|
-
|
41
|
-
(The MIT License)
|
42
|
-
|
43
|
-
Copyright (c) 2007-2012 Nick Sieger <nick@nicksieger.com>
|
44
|
-
|
45
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
46
|
-
a copy of this software and associated documentation files (the
|
47
|
-
'Software'), to deal in the Software without restriction, including
|
48
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
49
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
50
|
-
permit persons to whom the Software is furnished to do so, subject to
|
51
|
-
the following conditions:
|
52
|
-
|
53
|
-
The above copyright notice and this permission notice shall be
|
54
|
-
included in all copies or substantial portions of the Software.
|
55
|
-
|
56
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
57
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
58
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
59
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
60
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
61
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
62
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
DELETED
data/multipart-post.gemspec
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "multipart_post"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "multipart-post"
|
7
|
-
s.version = MultipartPost::VERSION
|
8
|
-
s.authors = ["Nick Sieger"]
|
9
|
-
s.email = ["nick@nicksieger.com"]
|
10
|
-
s.homepage = "https://github.com/nicksieger/multipart-post"
|
11
|
-
s.summary = %q{A multipart form post accessory for Net::HTTP.}
|
12
|
-
s.license = "MIT"
|
13
|
-
s.description = %q{Use with Net::HTTP to do multipart form posts. IO values that have #content_type, #original_filename, and #local_path will be posted as a binary file.}
|
14
|
-
|
15
|
-
s.rubyforge_project = "caldersphere"
|
16
|
-
|
17
|
-
s.files = `git ls-files`.split("\n")
|
18
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
-
s.require_paths = ["lib"]
|
21
|
-
end
|
data/test/multibyte.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ファイル
|
@@ -1,56 +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 'net/http/post/multipart'
|
8
|
-
require 'test/unit'
|
9
|
-
|
10
|
-
class Net::HTTP::Post::MultiPartTest < Test::Unit::TestCase
|
11
|
-
TEMP_FILE = "temp.txt"
|
12
|
-
|
13
|
-
HTTPPost = Struct.new("HTTPPost", :content_length, :body_stream, :content_type)
|
14
|
-
HTTPPost.module_eval do
|
15
|
-
def set_content_type(type, params = {})
|
16
|
-
self.content_type = type + params.map{|k,v|"; #{k}=#{v}"}.join('')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def teardown
|
21
|
-
File.delete(TEMP_FILE) rescue nil
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_form_multipart_body
|
25
|
-
File.open(TEMP_FILE, "w") {|f| f << "1234567890"}
|
26
|
-
@io = File.open(TEMP_FILE)
|
27
|
-
@io = UploadIO.new @io, "text/plain", TEMP_FILE
|
28
|
-
assert_results Net::HTTP::Post::Multipart.new("/foo/bar", :foo => 'bar', :file => @io)
|
29
|
-
end
|
30
|
-
def test_form_multipart_body_put
|
31
|
-
File.open(TEMP_FILE, "w") {|f| f << "1234567890"}
|
32
|
-
@io = File.open(TEMP_FILE)
|
33
|
-
@io = UploadIO.new @io, "text/plain", TEMP_FILE
|
34
|
-
assert_results Net::HTTP::Put::Multipart.new("/foo/bar", :foo => 'bar', :file => @io)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_form_multipart_body_with_stringio
|
38
|
-
@io = StringIO.new("1234567890")
|
39
|
-
@io = UploadIO.new @io, "text/plain", TEMP_FILE
|
40
|
-
assert_results Net::HTTP::Post::Multipart.new("/foo/bar", :foo => 'bar', :file => @io)
|
41
|
-
end
|
42
|
-
|
43
|
-
def assert_results(post)
|
44
|
-
assert post.content_length && post.content_length > 0
|
45
|
-
assert post.body_stream
|
46
|
-
assert_equal "multipart/form-data; boundary=#{Multipartable::DEFAULT_BOUNDARY}", post['content-type']
|
47
|
-
body = post.body_stream.read
|
48
|
-
boundary_regex = Regexp.quote Multipartable::DEFAULT_BOUNDARY
|
49
|
-
assert body =~ /1234567890/
|
50
|
-
# ensure there is at least one boundary
|
51
|
-
assert body =~ /^--#{boundary_regex}\r\n/
|
52
|
-
# ensure there is an epilogue
|
53
|
-
assert body =~ /^--#{boundary_regex}--\r\n/
|
54
|
-
assert body =~ /text\/plain/
|
55
|
-
end
|
56
|
-
end
|
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
|