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
|
## master
|
||||||
|
|
||||||
* [Process dynamic headers before making actual request](https://github.com/jnunemaker/httparty/pull/606)
|
* [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
|
## 0.16.2
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ module HTTParty
|
||||||
memo += %(Content-Disposition: form-data; name="#{key}")
|
memo += %(Content-Disposition: form-data; name="#{key}")
|
||||||
# value.path is used to support ActionDispatch::Http::UploadedFile
|
# value.path is used to support ActionDispatch::Http::UploadedFile
|
||||||
# https://github.com/jnunemaker/httparty/pull/585
|
# 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 += "\r\n"
|
||||||
memo += "Content-Type: application/octet-stream\r\n" if file?(value)
|
memo += "Content-Type: application/octet-stream\r\n" if file?(value)
|
||||||
memo += "\r\n"
|
memo += "\r\n"
|
||||||
|
@ -73,6 +73,10 @@ module HTTParty
|
||||||
end
|
end
|
||||||
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
|
attr_reader :params, :query_string_normalizer
|
||||||
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::ConnectionAdapter do
|
RSpec.describe HTTParty::ConnectionAdapter do
|
||||||
describe "initialization" 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
|
RSpec.describe HTTParty::CookieHash do
|
||||||
before(:each) 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
|
RSpec.describe HTTParty::Error do
|
||||||
subject { described_class }
|
subject { described_class }
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe HTTParty::HashConversions do
|
RSpec.describe HTTParty::HashConversions do
|
||||||
describe ".to_params" do
|
describe ".to_params" do
|
||||||
it "creates a params string from a hash" 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
|
RSpec.describe HTTParty::Logger::ApacheFormatter do
|
||||||
let(:subject) { described_class.new(logger_double, :info) }
|
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
|
RSpec.describe HTTParty::Logger::CurlFormatter do
|
||||||
describe "#format" 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
|
RSpec.describe HTTParty::Logger do
|
||||||
describe ".build" 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
|
RSpec.describe Net::HTTPHeader::DigestAuthenticator do
|
||||||
def setup_digest(response)
|
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
|
RSpec.describe HTTParty::Parser do
|
||||||
describe ".SupportedFormats" do
|
describe ".SupportedFormats" do
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require_relative '../../spec_helper'
|
require 'spec_helper'
|
||||||
|
require 'tempfile'
|
||||||
|
|
||||||
RSpec.describe HTTParty::Request::Body do
|
RSpec.describe HTTParty::Request::Body do
|
||||||
describe '#call' do
|
describe '#call' do
|
||||||
|
@ -18,26 +19,30 @@ RSpec.describe HTTParty::Request::Body do
|
||||||
|
|
||||||
context 'when params has file' do
|
context 'when params has file' do
|
||||||
before do
|
before do
|
||||||
allow(HTTParty::Request::MultipartBoundary).
|
allow(HTTParty::Request::MultipartBoundary)
|
||||||
to receive(:generate).and_return("------------------------c772861a5109d5ef")
|
.to receive(:generate).and_return("------------------------c772861a5109d5ef")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let(:file) { File.open('spec/fixtures/tiny.gif') }
|
||||||
let(:params) do
|
let(:params) do
|
||||||
{
|
{
|
||||||
user: {
|
user: {
|
||||||
avatar: File.open('spec/fixtures/tiny.gif'),
|
avatar: file,
|
||||||
first_name: 'John',
|
first_name: 'John',
|
||||||
last_name: 'Doe',
|
last_name: 'Doe',
|
||||||
enabled: true
|
enabled: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
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
|
let(:multipart_params) do
|
||||||
"--------------------------c772861a5109d5ef\r\n" \
|
"--------------------------c772861a5109d5ef\r\n" \
|
||||||
"Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"tiny.gif\"\r\n" \
|
"Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"#{expected_file_name}\"\r\n" \
|
||||||
"Content-Type: application/octet-stream\r\n" \
|
"Content-Type: #{expected_content_type}\r\n" \
|
||||||
"\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" \
|
"--------------------------c772861a5109d5ef\r\n" \
|
||||||
"Content-Disposition: form-data; name=\"user[first_name]\"\r\n" \
|
"Content-Disposition: form-data; name=\"user[first_name]\"\r\n" \
|
||||||
"\r\n" \
|
"\r\n" \
|
||||||
|
@ -54,6 +59,17 @@ RSpec.describe HTTParty::Request::Body do
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq multipart_params }
|
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
|
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
|
RSpec.describe HTTParty::Request do
|
||||||
before 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
|
RSpec.describe HTTParty::Response do
|
||||||
before 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
|
RSpec.describe HTTParty::Request do
|
||||||
context "SSL certificate verification" 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
|
RSpec.describe HTTParty do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@klass = Class.new
|
@klass = Class.new
|
||||||
|
|
Loading…
Reference in a new issue