multipart-post 1.1.2 → 1.1.4
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.
- data/.gitignore +5 -0
- data/.travis.yml +7 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +37 -0
- data/History.txt +33 -0
- data/Rakefile +6 -22
- data/lib/composite_io.rb +13 -6
- data/lib/multipart_post.rb +3 -0
- data/lib/multipartable.rb +2 -1
- data/lib/parts.rb +11 -4
- data/multipart-post.gemspec +20 -0
- data/test/multibyte.txt +1 -0
- metadata +41 -36
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
multipart-post (1.1.3)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
archive-tar-minitar (0.5.2)
|
10
|
+
columnize (0.3.1)
|
11
|
+
linecache (0.43)
|
12
|
+
linecache19 (0.5.11)
|
13
|
+
ruby_core_source (>= 0.1.4)
|
14
|
+
ruby-debug (0.10.3)
|
15
|
+
columnize (>= 0.1)
|
16
|
+
ruby-debug-base (~> 0.10.3.0)
|
17
|
+
ruby-debug-base (0.10.3)
|
18
|
+
linecache (>= 0.3)
|
19
|
+
ruby-debug-base19 (0.11.24)
|
20
|
+
columnize (>= 0.3.1)
|
21
|
+
linecache19 (>= 0.5.11)
|
22
|
+
ruby_core_source (>= 0.1.4)
|
23
|
+
ruby-debug19 (0.11.6)
|
24
|
+
columnize (>= 0.3.1)
|
25
|
+
linecache19 (>= 0.5.11)
|
26
|
+
ruby-debug-base19 (>= 0.11.19)
|
27
|
+
ruby_core_source (0.1.4)
|
28
|
+
archive-tar-minitar (>= 0.5.2)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
java
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
multipart-post!
|
36
|
+
ruby-debug
|
37
|
+
ruby-debug19
|
data/History.txt
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
=== 1.1.3 / 2011-07-25
|
2
|
+
|
3
|
+
- More configurable header specification for parts (Gerrit Riessen)
|
4
|
+
|
5
|
+
=== 1.1.2 / 2011-05-24
|
6
|
+
|
7
|
+
- Fix CRLF file part miscalculation (Johannes Wagener)
|
8
|
+
- Fix Epilogue CRLF issue (suggestion by Neil Spring)
|
9
|
+
|
10
|
+
=== 1.1.1 / 2011-05-13
|
11
|
+
|
12
|
+
- GH# 9: Fixed Ruby 1.9.2 StringIO bug (thanks Alex Koppel)
|
13
|
+
|
14
|
+
=== 1.1.0 / 2011-01-11
|
15
|
+
|
16
|
+
- API CHANGE: UploadIO.convert! removed in favor of UploadIO.new
|
17
|
+
(Jeff Hodges)
|
18
|
+
|
19
|
+
=== 1.0.1 / 2010-04-27
|
20
|
+
|
21
|
+
- Doc updates, make gemspec based on more modern Rubygems
|
22
|
+
|
23
|
+
=== 1.0 / 2009-02-12
|
24
|
+
|
25
|
+
- Many fixes from mlooney, seems to work now. Putting the 0.9 seal of
|
26
|
+
approval on it.
|
27
|
+
|
28
|
+
=== 0.1 / 2008-08-12
|
29
|
+
|
30
|
+
* 1 major enhancement
|
31
|
+
|
32
|
+
* Birthday!
|
33
|
+
|
data/Rakefile
CHANGED
@@ -1,25 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "bundler/gem_tasks"
|
2
2
|
|
3
|
-
|
4
|
-
require 'hoe'
|
5
|
-
require 'multipart_post'
|
3
|
+
task :default => :test
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
p.author = "Nick Sieger"
|
12
|
-
p.url = "http://github.com/nicksieger/multipart-post"
|
13
|
-
p.email = "nick@nicksieger.com"
|
14
|
-
p.description = "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."
|
15
|
-
p.summary = "Creates a multipart form post accessory for Net::HTTP."
|
16
|
-
end
|
17
|
-
hoe.spec.dependencies.delete_if { |dep| dep.name == "hoe" || dep.name == "rubyforge" }
|
18
|
-
|
19
|
-
task :gemspec do
|
20
|
-
File.open("#{hoe.name}.gemspec", "w") {|f| f << hoe.spec.to_ruby }
|
21
|
-
end
|
22
|
-
task :package => :gemspec
|
23
|
-
rescue LoadError
|
24
|
-
puts "You really need Hoe installed to be able to package this gem"
|
5
|
+
require 'rake/testtask'
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.test_files = FileList['test/**/test*.rb']
|
25
9
|
end
|
data/lib/composite_io.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# crio = CompositeReadIO.new(StringIO.new('one'), StringIO.new('two'), StringIO.new('three'))
|
13
13
|
# puts crio.read # => "onetwothree"
|
14
|
-
#
|
14
|
+
#
|
15
15
|
class CompositeReadIO
|
16
16
|
# Create a new composite-read IO from the arguments, all of which should
|
17
17
|
# respond to #read in a manner consistent with IO.
|
@@ -54,15 +54,21 @@ class UploadIO
|
|
54
54
|
# Net::HTTP::Post::Multipart.
|
55
55
|
#
|
56
56
|
# Can take two forms. The first accepts a filename and content type, and
|
57
|
-
# opens the file for reading (to be closed by finalizer).
|
58
|
-
#
|
59
|
-
#
|
57
|
+
# opens the file for reading (to be closed by finalizer).
|
58
|
+
#
|
59
|
+
# The second accepts an already-open IO, but also requires a third argument,
|
60
|
+
# the filename from which it was opened (particularly useful/recommended if
|
61
|
+
# uploading directly from a form in a framework, which often save the file to
|
62
|
+
# an arbitrarily named RackMultipart file in /tmp).
|
63
|
+
#
|
64
|
+
# Usage:
|
60
65
|
#
|
61
66
|
# UploadIO.new("file.txt", "text/plain")
|
62
67
|
# UploadIO.new(file_io, "text/plain", "file.txt")
|
63
|
-
|
68
|
+
#
|
69
|
+
attr_reader :content_type, :original_filename, :local_path, :io, :opts
|
64
70
|
|
65
|
-
def initialize(filename_or_io, content_type, filename = nil)
|
71
|
+
def initialize(filename_or_io, content_type, filename = nil, opts = {})
|
66
72
|
io = filename_or_io
|
67
73
|
local_path = ""
|
68
74
|
if io.respond_to? :read
|
@@ -79,6 +85,7 @@ class UploadIO
|
|
79
85
|
@original_filename = File.basename(filename)
|
80
86
|
@local_path = local_path
|
81
87
|
@io = io
|
88
|
+
@opts = opts
|
82
89
|
end
|
83
90
|
|
84
91
|
def self.convert!(io, content_type, original_filename, local_path)
|
data/lib/multipartable.rb
CHANGED
@@ -6,7 +6,8 @@ require 'parts'
|
|
6
6
|
parts = params.map {|k,v| Parts::Part.new(boundary, k, v)}
|
7
7
|
parts << Parts::EpiloguePart.new(boundary)
|
8
8
|
ios = parts.map{|p| p.to_io }
|
9
|
-
self.set_content_type("multipart/form-data",
|
9
|
+
self.set_content_type(headers["Content-Type"] || "multipart/form-data",
|
10
|
+
{ "boundary" => boundary })
|
10
11
|
self.content_length = parts.inject(0) {|sum,i| sum + i.length }
|
11
12
|
self.body_stream = CompositeReadIO.new(*ios)
|
12
13
|
end
|
data/lib/parts.rb
CHANGED
@@ -39,19 +39,26 @@ module Parts
|
|
39
39
|
attr_reader :length
|
40
40
|
def initialize(boundary, name, io)
|
41
41
|
file_length = io.respond_to?(:length) ? io.length : File.size(io.local_path)
|
42
|
-
@head = build_head(boundary, name, io.original_filename, io.content_type, file_length
|
42
|
+
@head = build_head(boundary, name, io.original_filename, io.content_type, file_length,
|
43
|
+
io.respond_to?(:opts) ? io.opts : {})
|
43
44
|
@foot = "\r\n"
|
44
45
|
@length = @head.length + file_length + @foot.length
|
45
46
|
@io = CompositeReadIO.new(StringIO.new(@head), io, StringIO.new(@foot))
|
46
47
|
end
|
47
48
|
|
48
|
-
def build_head(boundary, name, filename, type, content_len)
|
49
|
+
def build_head(boundary, name, filename, type, content_len, opts = {})
|
50
|
+
trans_encoding = opts["Content-Transfer-Encoding"] || "binary"
|
51
|
+
content_disposition = opts["Content-Disposition"] || "form-data"
|
52
|
+
|
49
53
|
part = ''
|
50
54
|
part << "--#{boundary}\r\n"
|
51
|
-
part << "Content-Disposition:
|
55
|
+
part << "Content-Disposition: #{content_disposition}; name=\"#{name.to_s}\"; filename=\"#{filename}\"\r\n"
|
52
56
|
part << "Content-Length: #{content_len}\r\n"
|
57
|
+
if content_id = opts["Content-ID"]
|
58
|
+
part << "Content-ID: #{content_id}\r\n"
|
59
|
+
end
|
53
60
|
part << "Content-Type: #{type}\r\n"
|
54
|
-
part << "Content-Transfer-Encoding:
|
61
|
+
part << "Content-Transfer-Encoding: #{trans_encoding}\r\n"
|
55
62
|
part << "\r\n"
|
56
63
|
end
|
57
64
|
end
|
@@ -0,0 +1,20 @@
|
|
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.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.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "caldersphere"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
data/test/multibyte.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ファイル
|
metadata
CHANGED
@@ -2,69 +2,74 @@
|
|
2
2
|
name: multipart-post
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.1.
|
5
|
+
version: 1.1.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
- Nick Sieger
|
8
|
+
- Nick Sieger
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-11-23 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: "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."
|
17
|
-
email:
|
17
|
+
email:
|
18
|
+
- nick@nicksieger.com
|
18
19
|
executables: []
|
19
20
|
|
20
21
|
extensions: []
|
21
22
|
|
22
|
-
extra_rdoc_files:
|
23
|
-
|
24
|
-
- README.txt
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
25
|
files:
|
26
|
-
-
|
27
|
-
-
|
28
|
-
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
- README.txt
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
|
26
|
+
- .gitignore
|
27
|
+
- .travis.yml
|
28
|
+
- Gemfile
|
29
|
+
- Gemfile.lock
|
30
|
+
- History.txt
|
31
|
+
- Manifest.txt
|
32
|
+
- README.txt
|
33
|
+
- Rakefile
|
34
|
+
- lib/composite_io.rb
|
35
|
+
- lib/multipart_post.rb
|
36
|
+
- lib/multipartable.rb
|
37
|
+
- lib/net/http/post/multipart.rb
|
38
|
+
- lib/parts.rb
|
39
|
+
- multipart-post.gemspec
|
40
|
+
- test/multibyte.txt
|
41
|
+
- test/net/http/post/test_multipart.rb
|
42
|
+
- test/test_composite_io.rb
|
43
|
+
- test/test_parts.rb
|
44
|
+
homepage: https://github.com/nicksieger/multipart-post
|
37
45
|
licenses: []
|
38
46
|
|
39
47
|
post_install_message:
|
40
|
-
rdoc_options:
|
41
|
-
|
42
|
-
- README.txt
|
48
|
+
rdoc_options: []
|
49
|
+
|
43
50
|
require_paths:
|
44
|
-
- lib
|
51
|
+
- lib
|
45
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
53
|
none: false
|
47
54
|
requirements:
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
segments:
|
52
|
-
- 0
|
53
|
-
version: "0"
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
54
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
59
|
none: false
|
56
60
|
requirements:
|
57
|
-
|
58
|
-
|
59
|
-
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
60
64
|
requirements: []
|
61
65
|
|
62
66
|
rubyforge_project: caldersphere
|
63
|
-
rubygems_version: 1.
|
67
|
+
rubygems_version: 1.8.9
|
64
68
|
signing_key:
|
65
69
|
specification_version: 3
|
66
|
-
summary:
|
70
|
+
summary: A multipart form post accessory for Net::HTTP.
|
67
71
|
test_files:
|
68
|
-
- test/
|
69
|
-
- test/
|
70
|
-
- test/
|
72
|
+
- test/multibyte.txt
|
73
|
+
- test/net/http/post/test_multipart.rb
|
74
|
+
- test/test_composite_io.rb
|
75
|
+
- test/test_parts.rb
|