Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FaradayStripeEncoder to encode all parameter styles #741

Merged
merged 1 commit into from
Feb 3, 2019

Conversation

brandur
Copy link
Contributor

@brandur brandur commented Feb 1, 2019

Makes a few tweaks to hopefully simplify clarity things:

  • FaradayStripeEncoder now becomes the way to encode all of form,
    multipart form, and query parameters.
  • Introduce a cache in it so that we don't have to encode everything
    twice (once for logging, and once for the request body).
  • Try to sanitize logging a bit by replacing Faraday::UploadIOs found
    in incoming parameters with a string representation of the file (note
    that all other styles of file input like File or Tempfile have
    been converted to Faraday::UploadIO by the time they reach the
    encoder).

r? @ob-stripe

Copy link
Contributor

@ob-stripe ob-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -794,6 +794,16 @@ class StripeClientTest < Test::Unit::TestCase
assert(!trace_payload["last_request_metrics"]["request_duration_ms"].nil?)
end
end

context "FaradayStripeEncoder" do
should "replace Faraday::UploadIO instances in parametes" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo here:

Suggested change
should "replace Faraday::UploadIO instances in parametes" do
should "replace Faraday::UploadIO instances in parameters" do

Makes a few tweaks to hopefully simplify clarity things:

* `FaradayStripeEncoder` now becomes the way to encode all of form,
  multipart form, and query parameters.
* Introduce a cache in it so that we don't have to encode everything
  twice (once for logging, and once for the request body).
* Try to sanitize logging a bit by replacing `Faraday::UploadIO`s found
  in incoming parameters with a string representation of the file (note
  that all other styles of file input like `File` or `Tempfile` have
  been converted to `Faraday::UploadIO` by the time they reach the
  encoder).
@brandur-stripe
Copy link
Contributor

Thanks OB, and nice catch on that typo!

@brandur-stripe brandur-stripe merged commit c1fa537 into master Feb 3, 2019
@brandur-stripe brandur-stripe deleted the brandur-simpler-encoding branch February 3, 2019 20:25
@brandur-stripe
Copy link
Contributor

Released as 4.8.0.

brandur-stripe pushed a commit that referenced this pull request Feb 11, 2019
In #741 I tried to do something too clever by replacing instances of
`Faraday::UploadIO` found in parameters with a human-readable string to
improve `STRIPE_LOG` logging output.

I thought I'd tested it at the time, but apparently not (or not well
enough), and this change caused the regression detailed in #742.

My findings about how Faraday encodes multipart were apparently wrong
and it does use these parameters, so here we remove the step where we
try to nicen them for logging. The logs look a little worse, but it's
not that big of a deal.

I've tested this patch against the API and confirmed that it addresses
the problem.

Fixes #742.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants