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.
@@ -0,0 +1,5 @@
1
+ doc
2
+ pkg
3
+ *~
4
+ *.swo
5
+ *.swp
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - jruby
5
+ branches:
6
+ only:
7
+ - master
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source :rubygems
2
+ gemspec
3
+
4
+ platforms :mri_19 do
5
+ gem 'ruby-debug19'
6
+ end
7
+
8
+ platforms :mri_18 do
9
+ gem 'ruby-debug'
10
+ end
11
+
@@ -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
@@ -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 'bundler/setup'
1
+ require "bundler/gem_tasks"
2
2
 
3
- begin
4
- require 'hoe'
5
- require 'multipart_post'
3
+ task :default => :test
6
4
 
7
- Hoe.plugin :rubyforge
8
- hoe = Hoe.spec("multipart-post") do |p|
9
- p.version = MultipartPost::VERSION
10
- p.rubyforge_name = "caldersphere"
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
@@ -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). The second accepts
58
- # an already-open IO, but also requires a third argument, the filename from
59
- # which it was opened.
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
- attr_reader :content_type, :original_filename, :local_path, :io
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)
@@ -0,0 +1,3 @@
1
+ module MultipartPost
2
+ VERSION = "1.1.4"
3
+ end
@@ -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", { "boundary" => boundary })
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
@@ -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: form-data; name=\"#{name.to_s}\"; filename=\"#{filename}\"\r\n"
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: binary\r\n"
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
@@ -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.2
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-05-24 00:00:00 Z
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: nick@nicksieger.com
17
+ email:
18
+ - nick@nicksieger.com
18
19
  executables: []
19
20
 
20
21
  extensions: []
21
22
 
22
- extra_rdoc_files:
23
- - Manifest.txt
24
- - README.txt
23
+ extra_rdoc_files: []
24
+
25
25
  files:
26
- - lib/composite_io.rb
27
- - lib/multipartable.rb
28
- - lib/parts.rb
29
- - lib/net/http/post/multipart.rb
30
- - Manifest.txt
31
- - Rakefile
32
- - README.txt
33
- - test/test_composite_io.rb
34
- - test/net/http/post/test_multipart.rb
35
- - test/test_parts.rb
36
- homepage: http://github.com/nicksieger/multipart-post
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
- - --main
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
- - !ruby/object:Gem::Version
50
- hash: 2078343466590708221
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
- - !ruby/object:Gem::Version
59
- version: "0"
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
60
64
  requirements: []
61
65
 
62
66
  rubyforge_project: caldersphere
63
- rubygems_version: 1.7.2
67
+ rubygems_version: 1.8.9
64
68
  signing_key:
65
69
  specification_version: 3
66
- summary: Creates a multipart form post accessory for Net::HTTP.
70
+ summary: A multipart form post accessory for Net::HTTP.
67
71
  test_files:
68
- - test/net/http/post/test_multipart.rb
69
- - test/test_composite_io.rb
70
- - test/test_parts.rb
72
+ - test/multibyte.txt
73
+ - test/net/http/post/test_multipart.rb
74
+ - test/test_composite_io.rb
75
+ - test/test_parts.rb