1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00

Multipart Payloads ignores the name attribute if it's not set

This commit is contained in:
Tekin 2010-03-22 17:43:41 +00:00 committed by Julien Kirch
parent 36eafc4f23
commit 6079fb070d
3 changed files with 17 additions and 1 deletions

View file

@ -1,6 +1,7 @@
# 1.4.3
- added Response.to_str and AbstractResponse.to_i to improve semantic and compatibility
- multipart Payloads ignores the name attribute if it's not set (patch provided by Tekin Suleyman)
# 1.4.2

View file

@ -149,7 +149,9 @@ module RestClient
def create_file_field(s, k, v)
begin
s.write("Content-Disposition: form-data; name=\"#{k}\"; filename=\"#{v.respond_to?(:original_filename) ? v.original_filename : File.basename(v.path)}\"#{EOL}")
s.write("Content-Disposition: form-data;")
s.write(" name=\"#{k}\";") unless (k.nil? || k=='')
s.write(" filename=\"#{v.respond_to?(:original_filename) ? v.original_filename : File.basename(v.path)}\"#{EOL}")
s.write("Content-Type: #{v.respond_to?(:content_type) ? v.content_type : mime_for(v.path)}#{EOL}")
s.write(EOL)
while data = v.read(8124)

View file

@ -77,6 +77,19 @@ Content-Type: image/jpeg\r
EOS
end
it "should ignore the name attribute when it's not set" do
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
m = RestClient::Payload::Multipart.new({nil => f})
m.to_s.should == <<-EOS
--#{m.boundary}\r
Content-Disposition: form-data; filename="master_shake.jpg"\r
Content-Type: image/jpeg\r
\r
#{IO.read(f.path)}\r
--#{m.boundary}--\r
EOS
end
it "should detect optional (original) content type and filename" do
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
f.instance_eval "def content_type; 'text/plain'; end"