diff --git a/lib/httparty/request/body.rb b/lib/httparty/request/body.rb index 7f02d47..58d6d9e 100644 --- a/lib/httparty/request/body.rb +++ b/lib/httparty/request/body.rb @@ -30,17 +30,17 @@ module HTTParty normalized_params = params.flat_map { |key, value| HashConversions.normalize_keys(key, value) } multipart = normalized_params.inject('') do |memo, (key, value)| - memo += "--#{boundary}\n" - memo += "Content-Disposition: form-data; name='#{key}'" - memo += "; filename='#{File.basename(value)}'" if file?(value) - memo += "\n" - memo += "Content-Type: application/octet-stream\n" if file?(value) - memo += "\n" + memo += "--#{boundary}\r\n" + memo += %(Content-Disposition: form-data; name="#{key}") + memo += %(; filename="#{File.basename(value)}") if file?(value) + memo += "\r\n" + memo += "Content-Type: application/octet-stream\r\n" if file?(value) + memo += "\r\n" memo += file?(value) ? value.read : value - memo += "\n" + memo += "\r\n" end - multipart += "--#{boundary}--\n" + multipart += "--#{boundary}--\r\n" end def has_file?(hash) diff --git a/spec/httparty/request/body_spec.rb b/spec/httparty/request/body_spec.rb index 9626c7c..669677c 100644 --- a/spec/httparty/request/body_spec.rb +++ b/spec/httparty/request/body_spec.rb @@ -32,20 +32,20 @@ RSpec.describe HTTParty::Request::Body do } end let(:multipart_params) do - "--------------------------c772861a5109d5ef\n" \ - "Content-Disposition: form-data; name='user[avatar]'; filename='tiny.gif'\n" \ - "Content-Type: application/octet-stream\n" \ - "\n" \ - "GIF89a\u0001\u0000\u0001\u0000\u0000\xFF\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0000;\n" \ - "--------------------------c772861a5109d5ef\n" \ - "Content-Disposition: form-data; name='user[first_name]'\n" \ - "\n" \ - "John\n" \ - "--------------------------c772861a5109d5ef\n" \ - "Content-Disposition: form-data; name='user[last_name]'\n" \ - "\n" \ - "Doe\n" \ - "--------------------------c772861a5109d5ef--\n" + "--------------------------c772861a5109d5ef\r\n" \ + "Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"tiny.gif\"\r\n" \ + "Content-Type: application/octet-stream\r\n" \ + "\r\n" \ + "GIF89a\u0001\u0000\u0001\u0000\u0000\xFF\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0000;\r\n" \ + "--------------------------c772861a5109d5ef\r\n" \ + "Content-Disposition: form-data; name=\"user[first_name]\"\r\n" \ + "\r\n" \ + "John\r\n" \ + "--------------------------c772861a5109d5ef\r\n" \ + "Content-Disposition: form-data; name=\"user[last_name]\"\r\n" \ + "\r\n" \ + "Doe\r\n" \ + "--------------------------c772861a5109d5ef--\r\n" end it { is_expected.to eq multipart_params }