Skip to content

Commit

Permalink
Loosen multipart content coupling to file system
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Milligan committed Sep 18, 2016
1 parent 5755f59 commit 7886408
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/rack/test/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,17 @@ def build_primitive_part(parameter_name, value)
end

def build_file_part(parameter_name, uploaded_file)
::File.open(uploaded_file.path, "rb") do |physical_file|
physical_file.set_encoding(Encoding::BINARY) if physical_file.respond_to?(:set_encoding)
uploaded_file.set_encoding(Encoding::BINARY) if uploaded_file.respond_to?(:set_encoding)
<<-EOF
--#{MULTIPART_BOUNDARY}\r
Content-Disposition: form-data; name="#{parameter_name}"; filename="#{escape(uploaded_file.original_filename)}"\r
Content-Type: #{uploaded_file.content_type}\r
Content-Length: #{::File.stat(uploaded_file.path).size}\r
Content-Length: #{uploaded_file.size}\r
\r
#{physical_file.read}\r
#{uploaded_file.read}\r
EOF
end
end

end

end
end

0 comments on commit 7886408

Please sign in to comment.