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 Faraday's Net::HTTP::Persistent adapter #698

Merged
merged 1 commit into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: ruby

rvm:
- 2.0
- 2.1
- 2.2
- 2.3
Expand Down
10 changes: 3 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ group :development do
end

platforms :mri do
# to avoid problems, bring Byebug in on just versions of Ruby under which
# it's known to work well
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new("2.0.0")
gem "byebug"
gem "pry"
gem "pry-byebug"
end
gem "byebug"
gem "pry"
gem "pry-byebug"
end
end
17 changes: 12 additions & 5 deletions lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ def self.default_conn
# of connection re-use, so make sure that we have a separate connection
# object per thread.
Thread.current[:stripe_client_default_conn] ||= begin
conn = Faraday.new do |c|
c.use Faraday::Request::Multipart
c.use Faraday::Request::UrlEncoded
c.use Faraday::Response::RaiseError
c.adapter Faraday.default_adapter
conn = Faraday.new do |builder|
Copy link
Contributor

Choose a reason for hiding this comment

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

Changed this variable name to builder to be more accurate and descriptive as to what's being received inside the block here.

builder.use Faraday::Request::Multipart
builder.use Faraday::Request::UrlEncoded
builder.use Faraday::Response::RaiseError

# Net::HTTP::Persistent doesn't seem to do well on JRuby, so fall
# back to default there.
if RUBY_PLATFORM == "java"
builder.adapter :net_http
else
builder.adapter :net_http_persistent
end
end

if Stripe.verify_ssl_certs
Expand Down
3 changes: 2 additions & 1 deletion stripe.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require "stripe/version"
Gem::Specification.new do |s|
s.name = "stripe"
s.version = Stripe::VERSION
s.required_ruby_version = ">= 2.0.0"
s.required_ruby_version = ">= 2.1.0"
s.summary = "Ruby bindings for the Stripe API"
s.description = "Stripe is the easiest way to accept payments online. See https://stripe.com for details."
s.author = "Stripe"
Expand All @@ -16,6 +16,7 @@ Gem::Specification.new do |s|
s.license = "MIT"

s.add_dependency("faraday", "~> 0.10")
s.add_dependency("net-http-persistent", "~> 3.0")

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- test/*`.split("\n")
Expand Down
3 changes: 2 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
# we can print one error and fail fast so that it's more clear to the user how
# they should fix the problem.
begin
resp = Faraday.get("http://localhost:#{MOCK_PORT}/")
conn = Faraday::Connection.new("http://localhost:#{MOCK_PORT}")
resp = conn.get("/")
Copy link
Contributor

@brandur-stripe brandur-stripe Nov 14, 2018

Choose a reason for hiding this comment

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

I had to change this because using the default connection at the beginning of the test run "locked" the middleware stack and prevented me from changing the adapter above. I guess it only worked before by virtue of the fact that all the middlewares we installed were default and thus already installed (so no changes to the middleware stack needed to be made).

version = resp.headers["Stripe-Mock-Version"]
if version != "master" &&
Gem::Version.new(version) < Gem::Version.new(MOCK_MINIMUM_VERSION)
Expand Down