Permalink
Browse files

Fix bugs. Ok, so it didn't work before now.

  • Loading branch information...
1 parent 4c2db18 commit e3451f540e1b55f06cd13d3179770e34512b4253 @nicksieger nicksieger committed Aug 12, 2008
Showing with 19 additions and 4 deletions.
  1. +1 −0 lib/composite_io.rb
  2. +18 −4 lib/net/http/post/multipart.rb
View
@@ -54,5 +54,6 @@ def local_path
"#{local_path}"
end
EOS
+ io
end
end
@@ -18,8 +18,8 @@ def length
def build_part(boundary, name, value)
part = ''
- part << "#{boundary}\r\n"
- part << "Content-Disposition: form-data; name=\"#{CGI::escape name.to_s}\"\r\n"
+ part << "--#{boundary}\r\n"
+ part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\r\n"
part << "\r\n"
part << "#{value}\r\n"
end
@@ -47,8 +47,8 @@ def length
def build_head(boundary, name, filename, type)
part = ''
- part << "#{boundary}\r\n"
- part << "Content-Disposition: form-data; name=\"#{CGI::escape name.to_s}\"; filename=\"#{filename}\"\r\n"
+ part << "--#{boundary}\r\n"
+ part << "Content-Disposition: form-data; name=\"#{name.to_s}\"; filename=\"#{filename}\"\r\n"
part << "Content-Type: #{type}\r\n"
part << "Content-Transfer-Encoding: binary\r\n"
part << "\r\n"
@@ -59,6 +59,19 @@ def to_io
end
end
+ class ClosingBoundary
+ def initialize(boundary)
+ @part = "--#{boundary}--\r\n"
+ @io = StringIO.new(@part)
+ end
+ def length
+ @part.length
+ end
+ def to_io
+ @io
+ end
+ end
+
class Part
def self.new(boundary, name, value)
if value.respond_to? :content_type
@@ -75,6 +88,7 @@ class Multipart < Post
def initialize(path, params, boundary = DEFAULT_BOUNDARY)
super(path)
parts = params.map {|k,v| Part.new(boundary, k, v)}
+ parts << ClosingBoundary.new(boundary)
ios = parts.map{|p| p.to_io }
self.set_content_type("multipart/form-data", { "boundary" => boundary })
self.content_length = parts.inject(0) {|sum,i| sum + i.length }

0 comments on commit e3451f5

Please sign in to comment.