mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Merge branch 'fix-action-dispatch-filename' of https://github.com/zherr/httparty into zherr-fix-action-dispatch-filename
This commit is contained in:
commit
1daeb55729
16 changed files with 72 additions and 51 deletions
|
@ -1,6 +1,7 @@
|
|||
## master
|
||||
|
||||
* [Process dynamic headers before making actual request](https://github.com/jnunemaker/httparty/pull/606)
|
||||
* [Fix multipart uploads with ActionDispatch::Http::UploadedFile TempFile by using original_filename](https://github.com/jnunemaker/httparty/pull/598)
|
||||
|
||||
## 0.16.2
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ module HTTParty
|
|||
memo += %(Content-Disposition: form-data; name="#{key}")
|
||||
# value.path is used to support ActionDispatch::Http::UploadedFile
|
||||
# https://github.com/jnunemaker/httparty/pull/585
|
||||
memo += %(; filename="#{File.basename(value.path)}") if file?(value)
|
||||
memo += %(; filename="#{determine_file_name(value)}") if file?(value)
|
||||
memo += "\r\n"
|
||||
memo += "Content-Type: application/octet-stream\r\n" if file?(value)
|
||||
memo += "\r\n"
|
||||
|
@ -73,6 +73,10 @@ module HTTParty
|
|||
end
|
||||
end
|
||||
|
||||
def determine_file_name(object)
|
||||
object.respond_to?(:original_filename) ? object.original_filename : File.basename(object.path)
|
||||
end
|
||||
|
||||
attr_reader :params, :query_string_normalizer
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe HTTParty::ConnectionAdapter do
|
||||
describe "initialization" do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe HTTParty::CookieHash do
|
||||
before(:each) do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe HTTParty::Error do
|
||||
subject { described_class }
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe HTTParty::HashConversions do
|
||||
describe ".to_params" do
|
||||
it "creates a params string from a hash" do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe HTTParty::Logger::ApacheFormatter do
|
||||
let(:subject) { described_class.new(logger_double, :info) }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe HTTParty::Logger::CurlFormatter do
|
||||
describe "#format" do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe HTTParty::Logger do
|
||||
describe ".build" do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe Net::HTTPHeader::DigestAuthenticator do
|
||||
def setup_digest(response)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe HTTParty::Parser do
|
||||
describe ".SupportedFormats" do
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require_relative '../../spec_helper'
|
||||
require 'spec_helper'
|
||||
require 'tempfile'
|
||||
|
||||
RSpec.describe HTTParty::Request::Body do
|
||||
describe '#call' do
|
||||
|
@ -18,26 +19,30 @@ RSpec.describe HTTParty::Request::Body do
|
|||
|
||||
context 'when params has file' do
|
||||
before do
|
||||
allow(HTTParty::Request::MultipartBoundary).
|
||||
to receive(:generate).and_return("------------------------c772861a5109d5ef")
|
||||
allow(HTTParty::Request::MultipartBoundary)
|
||||
.to receive(:generate).and_return("------------------------c772861a5109d5ef")
|
||||
end
|
||||
|
||||
let(:file) { File.open('spec/fixtures/tiny.gif') }
|
||||
let(:params) do
|
||||
{
|
||||
user: {
|
||||
avatar: File.open('spec/fixtures/tiny.gif'),
|
||||
avatar: file,
|
||||
first_name: 'John',
|
||||
last_name: 'Doe',
|
||||
enabled: true
|
||||
}
|
||||
}
|
||||
end
|
||||
let(:expected_file_name) { 'tiny.gif' }
|
||||
let(:expected_file_contents) { "GIF89a\u0001\u0000\u0001\u0000\u0000\xFF\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0000;" }
|
||||
let(:expected_content_type) { 'application/octet-stream' }
|
||||
let(:multipart_params) do
|
||||
"--------------------------c772861a5109d5ef\r\n" \
|
||||
"Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"tiny.gif\"\r\n" \
|
||||
"Content-Type: application/octet-stream\r\n" \
|
||||
"Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"#{expected_file_name}\"\r\n" \
|
||||
"Content-Type: #{expected_content_type}\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" \
|
||||
"#{expected_file_contents}\r\n" \
|
||||
"--------------------------c772861a5109d5ef\r\n" \
|
||||
"Content-Disposition: form-data; name=\"user[first_name]\"\r\n" \
|
||||
"\r\n" \
|
||||
|
@ -54,6 +59,17 @@ RSpec.describe HTTParty::Request::Body do
|
|||
end
|
||||
|
||||
it { is_expected.to eq multipart_params }
|
||||
|
||||
context 'file object responds to original_filename' do
|
||||
let(:some_temp_file) { Tempfile.new('some_temp_file.gif') }
|
||||
let(:expected_file_name) { "some_temp_file.gif" }
|
||||
let(:expected_file_contents) { "Hello" }
|
||||
let(:file) { double(:mocked_action_dispatch, path: some_temp_file.path, original_filename: 'some_temp_file.gif', read: expected_file_contents) }
|
||||
|
||||
before { some_temp_file.write('Hello') }
|
||||
|
||||
it { is_expected.to eq multipart_params }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe HTTParty::Request do
|
||||
before do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe HTTParty::Response do
|
||||
before do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe HTTParty::Request do
|
||||
context "SSL certificate verification" do
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
||||
|
||||
RSpec.describe HTTParty do
|
||||
before(:each) do
|
||||
@klass = Class.new
|
||||
|
|
Loading…
Reference in a new issue