Merge pull request #743 from stripe/brandur-remove-file-encoding

Remove attempt to nicen `UploadIO` in logs
This commit is contained in:
Brandur 2019-02-11 11:22:55 -08:00 committed by GitHub
commit 65cc699832
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 31 deletions

View File

@ -219,7 +219,7 @@ module Stripe
# will throw away the result of this encoder and build its body.
def encode(hash)
@cache.fetch(hash) do |k|
@cache[k] = Util.encode_parameters(replace_faraday_io(hash))
@cache[k] = Util.encode_parameters(hash)
end
end
@ -227,26 +227,6 @@ module Stripe
def decode(_str)
raise NotImplementedError, "#{self.class.name} does not implement #decode"
end
# Replaces instances of `Faraday::UploadIO` with a simple string
# representation so that they'll log a little better. Faraday won't use
# these parameters, so it's okay that we did this.
#
# Unfortunately the string representation still doesn't look very nice
# because we still URL-encode special symbols in the final value. It's
# possible we could stop doing this and just leave it to Faraday to do
# the right thing.
private def replace_faraday_io(value)
if value.is_a?(Array)
value.each_with_index { |v, i| value[i] = replace_faraday_io(v) }
elsif value.is_a?(Hash)
value.each { |k, v| value[k] = replace_faraday_io(v) }
elsif value.is_a?(Faraday::UploadIO)
"FILE:#{value.original_filename}"
else
value
end
end
end
def api_url(url = "", api_base = nil)

View File

@ -794,16 +794,6 @@ module Stripe
assert(!trace_payload["last_request_metrics"]["request_duration_ms"].nil?)
end
end
context "FaradayStripeEncoder" do
should "replace Faraday::UploadIO instances in parameters" do
encoder = StripeClient::FaradayStripeEncoder.new
encoded = encoder.encode(foo: [
{ file: Faraday::UploadIO.new(::File.new(__FILE__), nil) },
])
assert_equal "foo[0][file]=FILE%3Astripe_client_test.rb", encoded
end
end
end
class SystemProfilerTest < Test::Unit::TestCase