multipart-post 2.0.0 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- 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 +86 -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 -29
- data/lib/net/http/post/multipart.rb +29 -15
- data/lib/parts.rb +2 -96
- data.tar.gz.sig +0 -0
- metadata +114 -49
- metadata.gz.sig +0 -0
- data/.gitignore +0 -6
- data/.travis.yml +0 -7
- data/Gemfile +0 -14
- data/History.txt +0 -60
- data/Manifest.txt +0 -9
- data/README.md +0 -77
- data/Rakefile +0 -9
- data/multipart-post.gemspec +0 -22
- data/test/multibyte.txt +0 -1
- data/test/net/http/post/test_multipart.rb +0 -110
- data/test/test_composite_io.rb +0 -115
- data/test/test_parts.rb +0 -86
data/lib/parts.rb
CHANGED
@@ -1,96 +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, headers = {})
|
10
|
-
headers ||= {} # avoid nil values
|
11
|
-
if file?(value)
|
12
|
-
FilePart.new(boundary, name, value, headers)
|
13
|
-
else
|
14
|
-
ParamPart.new(boundary, name, value, headers)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.file?(value)
|
19
|
-
value.respond_to?(:content_type) && value.respond_to?(:original_filename)
|
20
|
-
end
|
21
|
-
|
22
|
-
def length
|
23
|
-
@part.length
|
24
|
-
end
|
25
|
-
|
26
|
-
def to_io
|
27
|
-
@io
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class ParamPart
|
32
|
-
include Part
|
33
|
-
def initialize(boundary, name, value, headers = {})
|
34
|
-
@part = build_part(boundary, name, value, headers)
|
35
|
-
@io = StringIO.new(@part)
|
36
|
-
end
|
37
|
-
|
38
|
-
def length
|
39
|
-
@part.bytesize
|
40
|
-
end
|
41
|
-
|
42
|
-
def build_part(boundary, name, value, headers = {})
|
43
|
-
part = ''
|
44
|
-
part << "--#{boundary}\r\n"
|
45
|
-
part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\r\n"
|
46
|
-
part << "Content-Type: #{headers["Content-Type"]}\r\n" if headers["Content-Type"]
|
47
|
-
part << "\r\n"
|
48
|
-
part << "#{value}\r\n"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Represents a part to be filled from file IO.
|
53
|
-
class FilePart
|
54
|
-
include Part
|
55
|
-
attr_reader :length
|
56
|
-
def initialize(boundary, name, io, headers = {})
|
57
|
-
file_length = io.respond_to?(:length) ? io.length : File.size(io.local_path)
|
58
|
-
@head = build_head(boundary, name, io.original_filename, io.content_type, file_length,
|
59
|
-
io.respond_to?(:opts) ? io.opts.merge(headers) : headers)
|
60
|
-
@foot = "\r\n"
|
61
|
-
@length = @head.bytesize + file_length + @foot.length
|
62
|
-
@io = CompositeReadIO.new(StringIO.new(@head), io, StringIO.new(@foot))
|
63
|
-
end
|
64
|
-
|
65
|
-
def build_head(boundary, name, filename, type, content_len, opts = {}, headers = {})
|
66
|
-
trans_encoding = opts["Content-Transfer-Encoding"] || "binary"
|
67
|
-
content_disposition = opts["Content-Disposition"] || "form-data"
|
68
|
-
|
69
|
-
part = ''
|
70
|
-
part << "--#{boundary}\r\n"
|
71
|
-
part << "Content-Disposition: #{content_disposition}; name=\"#{name.to_s}\"; filename=\"#{filename}\"\r\n"
|
72
|
-
part << "Content-Length: #{content_len}\r\n"
|
73
|
-
if content_id = opts["Content-ID"]
|
74
|
-
part << "Content-ID: #{content_id}\r\n"
|
75
|
-
end
|
76
|
-
|
77
|
-
if headers["Content-Type"] != nil
|
78
|
-
part << "Content-Type: " + headers["Content-Type"] + "\r\n"
|
79
|
-
else
|
80
|
-
part << "Content-Type: #{type}\r\n"
|
81
|
-
end
|
82
|
-
|
83
|
-
part << "Content-Transfer-Encoding: #{trans_encoding}\r\n"
|
84
|
-
part << "\r\n"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# Represents the epilogue or closing boundary.
|
89
|
-
class EpiloguePart
|
90
|
-
include Part
|
91
|
-
def initialize(boundary)
|
92
|
-
@part = "--#{boundary}--\r\n\r\n"
|
93
|
-
@io = StringIO.new(@part)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
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
Binary file
|
metadata
CHANGED
@@ -1,79 +1,144 @@
|
|
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.2.3
|
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-10 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: rspec
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.4'
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.4'
|
104
|
+
description:
|
16
105
|
email:
|
17
|
-
- nick@nicksieger.com
|
18
106
|
executables: []
|
19
107
|
extensions: []
|
20
108
|
extra_rdoc_files: []
|
21
109
|
files:
|
22
|
-
- .gitignore
|
23
|
-
- .travis.yml
|
24
|
-
- Gemfile
|
25
|
-
- History.txt
|
26
|
-
- Manifest.txt
|
27
|
-
- README.md
|
28
|
-
- Rakefile
|
29
110
|
- lib/composite_io.rb
|
111
|
+
- lib/multipart/post.rb
|
112
|
+
- lib/multipart/post/composite_read_io.rb
|
113
|
+
- lib/multipart/post/multipartable.rb
|
114
|
+
- lib/multipart/post/parts.rb
|
115
|
+
- lib/multipart/post/upload_io.rb
|
116
|
+
- lib/multipart/post/version.rb
|
30
117
|
- lib/multipart_post.rb
|
31
118
|
- lib/multipartable.rb
|
32
119
|
- lib/net/http/post/multipart.rb
|
33
120
|
- lib/parts.rb
|
34
|
-
|
35
|
-
- test/multibyte.txt
|
36
|
-
- test/net/http/post/test_multipart.rb
|
37
|
-
- test/test_composite_io.rb
|
38
|
-
- test/test_parts.rb
|
39
|
-
homepage: https://github.com/nicksieger/multipart-post
|
121
|
+
homepage: https://github.com/socketry/multipart-post
|
40
122
|
licenses:
|
41
123
|
- MIT
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
- README.md
|
46
|
-
- -SHN
|
47
|
-
- -f
|
48
|
-
- darkfish
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
49
127
|
require_paths:
|
50
128
|
- lib
|
51
129
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
130
|
requirements:
|
54
|
-
- -
|
131
|
+
- - ">="
|
55
132
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
57
|
-
segments:
|
58
|
-
- 0
|
59
|
-
hash: 3851181222699685043
|
133
|
+
version: 2.3.0
|
60
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
135
|
requirements:
|
63
|
-
- -
|
136
|
+
- - ">="
|
64
137
|
- !ruby/object:Gem::Version
|
65
138
|
version: '0'
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
hash: 3851181222699685043
|
69
139
|
requirements: []
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
specification_version: 3
|
140
|
+
rubygems_version: 3.1.6
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
74
143
|
summary: A multipart form post accessory for Net::HTTP.
|
75
|
-
test_files:
|
76
|
-
- test/multibyte.txt
|
77
|
-
- test/net/http/post/test_multipart.rb
|
78
|
-
- test/test_composite_io.rb
|
79
|
-
- test/test_parts.rb
|
144
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/History.txt
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
=== 2.0.0 / 2013-12-21
|
2
|
-
|
3
|
-
- Drop Ruby 1.8 compatibility
|
4
|
-
- GH #21: Fix FilePart length calculation for Ruby 1.9 when filename contains
|
5
|
-
multibyte characters (hexfet)
|
6
|
-
- GH #20: Ensure upload responds to both #content_type and #original_filename
|
7
|
-
(Steven Davidovitz)
|
8
|
-
- GH #31: Support setting headers on any part of the request (Socrates Vicente)
|
9
|
-
- GH #30: Support array values for params (Gustav Ernberg)
|
10
|
-
- GH #32: Fix respond_to? signature (Leo Cassarani)
|
11
|
-
- GH #33: Update README to markdown (Jagtesh Chadha)
|
12
|
-
- GH #35: Improved handling of array-type parameters (Steffen Grunwald)
|
13
|
-
|
14
|
-
=== 1.2.0 / 2013-02-25
|
15
|
-
|
16
|
-
- #25: Ruby 2 compatibility (thanks mislav)
|
17
|
-
|
18
|
-
=== 1.1.5 / 2012-02-12
|
19
|
-
|
20
|
-
- Fix length/bytesize of parts in 1.9 (#7, #14) (Jason Moore)
|
21
|
-
- Allow CompositeIO objects to be re-read by rewinding, like other IO
|
22
|
-
objects. (Luke Redpath)
|
23
|
-
|
24
|
-
=== 1.1.4 / 2011-11-23
|
25
|
-
|
26
|
-
- Non-functional changes in release (switch to Bundler gem tasks)
|
27
|
-
|
28
|
-
=== 1.1.3 / 2011-07-25
|
29
|
-
|
30
|
-
- More configurable header specification for parts (Gerrit Riessen)
|
31
|
-
|
32
|
-
=== 1.1.2 / 2011-05-24
|
33
|
-
|
34
|
-
- Fix CRLF file part miscalculation (Johannes Wagener)
|
35
|
-
- Fix Epilogue CRLF issue (suggestion by Neil Spring)
|
36
|
-
|
37
|
-
=== 1.1.1 / 2011-05-13
|
38
|
-
|
39
|
-
- GH# 9: Fixed Ruby 1.9.2 StringIO bug (thanks Alex Koppel)
|
40
|
-
|
41
|
-
=== 1.1.0 / 2011-01-11
|
42
|
-
|
43
|
-
- API CHANGE: UploadIO.convert! removed in favor of UploadIO.new
|
44
|
-
(Jeff Hodges)
|
45
|
-
|
46
|
-
=== 1.0.1 / 2010-04-27
|
47
|
-
|
48
|
-
- Doc updates, make gemspec based on more modern Rubygems
|
49
|
-
|
50
|
-
=== 1.0 / 2009-02-12
|
51
|
-
|
52
|
-
- Many fixes from mlooney, seems to work now. Putting the 0.9 seal of
|
53
|
-
approval on it.
|
54
|
-
|
55
|
-
=== 0.1 / 2008-08-12
|
56
|
-
|
57
|
-
* 1 major enhancement
|
58
|
-
|
59
|
-
* Birthday!
|
60
|
-
|
data/Manifest.txt
DELETED
data/README.md
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
## multipart-post
|
2
|
-
|
3
|
-
* http://github.com/nicksieger/multipart-post
|
4
|
-
|
5
|
-
![build status](https://travis-ci.org/nicksieger/multipart-post.png)
|
6
|
-
|
7
|
-
#### DESCRIPTION:
|
8
|
-
|
9
|
-
Adds a streamy multipart form post capability to Net::HTTP. Also
|
10
|
-
supports other methods besides POST.
|
11
|
-
|
12
|
-
#### FEATURES/PROBLEMS:
|
13
|
-
|
14
|
-
* Appears to actually work. A good feature to have.
|
15
|
-
* Encapsulates posting of file/binary parts and name/value parameter parts, similar to
|
16
|
-
most browsers' file upload forms.
|
17
|
-
* Provides an UploadIO helper class to prepare IO objects for inclusion in the params
|
18
|
-
hash of the multipart post object.
|
19
|
-
|
20
|
-
#### SYNOPSIS:
|
21
|
-
|
22
|
-
require 'net/http/post/multipart'
|
23
|
-
|
24
|
-
url = URI.parse('http://www.example.com/upload')
|
25
|
-
File.open("./image.jpg") do |jpg|
|
26
|
-
req = Net::HTTP::Post::Multipart.new url.path,
|
27
|
-
"file" => UploadIO.new(jpg, "image/jpeg", "image.jpg")
|
28
|
-
res = Net::HTTP.start(url.host, url.port) do |http|
|
29
|
-
http.request(req)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
To post multiple files or attachments, simply include multiple parameters with
|
34
|
-
UploadIO values:
|
35
|
-
|
36
|
-
require 'net/http/post/multipart'
|
37
|
-
|
38
|
-
url = URI.parse('http://www.example.com/upload')
|
39
|
-
req = Net::HTTP::Post::Multipart.new url.path,
|
40
|
-
"file1" => UploadIO.new(File.new("./image.jpg"), "image/jpeg", "image.jpg"),
|
41
|
-
"file2" => UploadIO.new(File.new("./image2.jpg"), "image/jpeg", "image2.jpg")
|
42
|
-
res = Net::HTTP.start(url.host, url.port) do |http|
|
43
|
-
http.request(req)
|
44
|
-
end
|
45
|
-
|
46
|
-
#### REQUIREMENTS:
|
47
|
-
|
48
|
-
None
|
49
|
-
|
50
|
-
#### INSTALL:
|
51
|
-
|
52
|
-
gem install multipart-post
|
53
|
-
|
54
|
-
#### LICENSE:
|
55
|
-
|
56
|
-
(The MIT License)
|
57
|
-
|
58
|
-
Copyright (c) 2007-2013 Nick Sieger <nick@nicksieger.com>
|
59
|
-
|
60
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
61
|
-
a copy of this software and associated documentation files (the
|
62
|
-
'Software'), to deal in the Software without restriction, including
|
63
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
64
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
65
|
-
permit persons to whom the Software is furnished to do so, subject to
|
66
|
-
the following conditions:
|
67
|
-
|
68
|
-
The above copyright notice and this permission notice shall be
|
69
|
-
included in all copies or substantial portions of the Software.
|
70
|
-
|
71
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
72
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
73
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
74
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
75
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
76
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
77
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
DELETED
data/multipart-post.gemspec
DELETED
@@ -1,22 +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.rdoc_options = ["--main", "README.md", "-SHN", "-f", "darkfish"]
|
21
|
-
s.require_paths = ["lib"]
|
22
|
-
end
|
data/test/multibyte.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ファイル
|
@@ -1,110 +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 '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 test_form_multiparty_body_with_parts_headers
|
44
|
-
@io = StringIO.new("1234567890")
|
45
|
-
@io = UploadIO.new @io, "text/plain", TEMP_FILE
|
46
|
-
parts = { :text => 'bar', :file => @io }
|
47
|
-
headers = {
|
48
|
-
:parts => {
|
49
|
-
:text => { "Content-Type" => "part/type" },
|
50
|
-
:file => { "Content-Transfer-Encoding" => "part-encoding" }
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
request = Net::HTTP::Post::Multipart.new("/foo/bar", parts, headers)
|
55
|
-
assert_results request
|
56
|
-
assert_additional_headers_added(request, headers[:parts])
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_form_multipart_body_with_array_value
|
60
|
-
File.open(TEMP_FILE, "w") {|f| f << "1234567890"}
|
61
|
-
@io = File.open(TEMP_FILE)
|
62
|
-
@io = UploadIO.new @io, "text/plain", TEMP_FILE
|
63
|
-
params = {:foo => ['bar', 'quux'], :file => @io}
|
64
|
-
headers = { :parts => {
|
65
|
-
:foo => { "Content-Type" => "application/json; charset=UTF-8" } } }
|
66
|
-
post = Net::HTTP::Post::Multipart.new("/foo/bar", params, headers,
|
67
|
-
Net::HTTP::Post::Multipart::DEFAULT_BOUNDARY)
|
68
|
-
|
69
|
-
assert post.content_length && post.content_length > 0
|
70
|
-
assert post.body_stream
|
71
|
-
|
72
|
-
body = post.body_stream.read
|
73
|
-
assert_equal 2, body.lines.grep(/name="foo"/).length
|
74
|
-
assert body =~ /Content-Type: application\/json; charset=UTF-8/, body
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_form_multipart_body_with_arrayparam
|
78
|
-
File.open(TEMP_FILE, "w") {|f| f << "1234567890"}
|
79
|
-
@io = File.open(TEMP_FILE)
|
80
|
-
@io = UploadIO.new @io, "text/plain", TEMP_FILE
|
81
|
-
assert_results Net::HTTP::Post::Multipart.new("/foo/bar", :multivalueParam => ['bar','bah'], :file => @io)
|
82
|
-
end
|
83
|
-
|
84
|
-
def assert_results(post)
|
85
|
-
assert post.content_length && post.content_length > 0
|
86
|
-
assert post.body_stream
|
87
|
-
assert_equal "multipart/form-data; boundary=#{Multipartable::DEFAULT_BOUNDARY}", post['content-type']
|
88
|
-
body = post.body_stream.read
|
89
|
-
boundary_regex = Regexp.quote Multipartable::DEFAULT_BOUNDARY
|
90
|
-
assert body =~ /1234567890/
|
91
|
-
# ensure there is at least one boundary
|
92
|
-
assert body =~ /^--#{boundary_regex}\r\n/
|
93
|
-
# ensure there is an epilogue
|
94
|
-
assert body =~ /^--#{boundary_regex}--\r\n/
|
95
|
-
assert body =~ /text\/plain/
|
96
|
-
if (body =~ /multivalueParam/)
|
97
|
-
assert_equal 2, body.scan(/^.*multivalueParam.*$/).size
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def assert_additional_headers_added(post, parts_headers)
|
102
|
-
post.body_stream.rewind
|
103
|
-
body = post.body_stream.read
|
104
|
-
parts_headers.each do |part, headers|
|
105
|
-
headers.each do |k,v|
|
106
|
-
assert body =~ /#{k}: #{v}/
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|