multipart-post 1.1.1 → 1.1.2
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/lib/parts.rb +4 -3
- data/test/test_parts.rb +23 -0
- metadata +5 -3
data/lib/parts.rb
CHANGED
@@ -40,8 +40,9 @@ module Parts
|
|
40
40
|
def initialize(boundary, name, io)
|
41
41
|
file_length = io.respond_to?(:length) ? io.length : File.size(io.local_path)
|
42
42
|
@head = build_head(boundary, name, io.original_filename, io.content_type, file_length)
|
43
|
-
@
|
44
|
-
@
|
43
|
+
@foot = "\r\n"
|
44
|
+
@length = @head.length + file_length + @foot.length
|
45
|
+
@io = CompositeReadIO.new(StringIO.new(@head), io, StringIO.new(@foot))
|
45
46
|
end
|
46
47
|
|
47
48
|
def build_head(boundary, name, filename, type, content_len)
|
@@ -59,7 +60,7 @@ module Parts
|
|
59
60
|
class EpiloguePart
|
60
61
|
include Part
|
61
62
|
def initialize(boundary)
|
62
|
-
@part = "--#{boundary}--\r\n"
|
63
|
+
@part = "--#{boundary}--\r\n\r\n"
|
63
64
|
@io = StringIO.new(@part)
|
64
65
|
end
|
65
66
|
end
|
data/test/test_parts.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require 'parts'
|
4
|
+
require 'stringio'
|
5
|
+
require 'composite_io'
|
6
|
+
|
7
|
+
class FilePartTest < Test::Unit::TestCase
|
8
|
+
TEMP_FILE = "temp.txt"
|
9
|
+
|
10
|
+
def setup
|
11
|
+
File.open(TEMP_FILE, "w") {|f| f << "1234567890"}
|
12
|
+
io = UploadIO.new(TEMP_FILE, "text/plain")
|
13
|
+
@part = Parts::FilePart.new("boundary", "afile", io)
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
File.delete(TEMP_FILE) rescue nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_correct_length
|
21
|
+
assert_equal @part.length, @part.to_io.read.length
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: multipart-post
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.1.
|
5
|
+
version: 1.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nick Sieger
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-24 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."
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- README.txt
|
33
33
|
- test/test_composite_io.rb
|
34
34
|
- test/net/http/post/test_multipart.rb
|
35
|
+
- test/test_parts.rb
|
35
36
|
homepage: http://github.com/nicksieger/multipart-post
|
36
37
|
licenses: []
|
37
38
|
|
@@ -46,7 +47,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
47
|
requirements:
|
47
48
|
- - ">="
|
48
49
|
- !ruby/object:Gem::Version
|
49
|
-
hash:
|
50
|
+
hash: 2078343466590708221
|
50
51
|
segments:
|
51
52
|
- 0
|
52
53
|
version: "0"
|
@@ -66,3 +67,4 @@ summary: Creates a multipart form post accessory for Net::HTTP.
|
|
66
67
|
test_files:
|
67
68
|
- test/net/http/post/test_multipart.rb
|
68
69
|
- test/test_composite_io.rb
|
70
|
+
- test/test_parts.rb
|