Add faraday 2 support

This commit is contained in:
Benjamin Neff 2022-07-03 04:31:23 +02:00
parent a0e1cac95f
commit bb12f93bd0
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
5 changed files with 20 additions and 41 deletions

View file

@ -2,8 +2,8 @@ PATH
remote: . remote: .
specs: specs:
diaspora_federation (0.3.0) diaspora_federation (0.3.0)
faraday (~> 1.0) faraday (>= 1.0, < 3)
faraday_middleware (~> 1.0) faraday-follow_redirects (~> 0.3)
nokogiri (~> 1.6, >= 1.6.8) nokogiri (~> 1.6, >= 1.6.8)
typhoeus (~> 1.0) typhoeus (~> 1.0)
valid (~> 1.0) valid (~> 1.0)
@ -53,27 +53,12 @@ GEM
ethon (0.15.0) ethon (0.15.0)
ffi (>= 1.15.0) ffi (>= 1.15.0)
fabrication (2.27.0) fabrication (2.27.0)
faraday (1.8.0) faraday (2.3.0)
faraday-em_http (~> 1.0) faraday-net_http (~> 2.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0.1)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.1)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
multipart-post (>= 1.2, < 3)
ruby2_keywords (>= 0.0.4) ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0) faraday-follow_redirects (0.3.0)
faraday-em_synchrony (1.0.0) faraday (>= 1, < 3)
faraday-excon (1.1.0) faraday-net_http (2.0.3)
faraday-httpclient (1.0.1)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday_middleware (1.2.0)
faraday (~> 1.0)
ffi (1.15.4) ffi (1.15.4)
fuubar (2.5.1) fuubar (2.5.1)
rspec-core (~> 3.0) rspec-core (~> 3.0)
@ -107,15 +92,14 @@ GEM
mini_portile2 (2.8.0) mini_portile2 (2.8.0)
minitest (5.16.2) minitest (5.16.2)
multi_xml (0.6.0) multi_xml (0.6.0)
multipart-post (2.1.1)
nokogiri (1.13.7) nokogiri (1.13.7)
mini_portile2 (~> 2.8.0) mini_portile2 (~> 2.8.0)
racc (~> 1.4) racc (~> 1.4)
nyan-cat-formatter (0.12.0) nyan-cat-formatter (0.12.0)
rspec (>= 2.99, >= 2.14.2, < 4) rspec (>= 2.99, >= 2.14.2, < 4)
octokit (4.21.0) octokit (4.25.1)
faraday (>= 0.9) faraday (>= 1, < 3)
sawyer (~> 0.8.0, >= 0.5.3) sawyer (~> 0.9)
parallel (1.21.0) parallel (1.21.0)
parser (3.0.3.0) parser (3.0.3.0)
ast (~> 2.4.1) ast (~> 2.4.1)
@ -136,7 +120,7 @@ GEM
pry-byebug (3.8.0) pry-byebug (3.8.0)
byebug (~> 11.0) byebug (~> 11.0)
pry (~> 0.10) pry (~> 0.10)
public_suffix (4.0.6) public_suffix (4.0.7)
racc (1.6.0) racc (1.6.0)
rack (2.2.4) rack (2.2.4)
rack-test (2.0.2) rack-test (2.0.2)
@ -204,9 +188,9 @@ GEM
ruby-progressbar (1.11.0) ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5) ruby2_keywords (0.0.5)
rugged (1.0.1) rugged (1.0.1)
sawyer (0.8.2) sawyer (0.9.2)
addressable (>= 2.3.5) addressable (>= 2.3.5)
faraday (> 0.8, < 2.0) faraday (>= 0.17.3, < 3)
simplecov (0.21.2) simplecov (0.21.2)
docile (~> 1.1) docile (~> 1.1)
simplecov-html (~> 0.11) simplecov-html (~> 0.11)

View file

@ -29,8 +29,8 @@ Gem::Specification.new do |s|
s.required_ruby_version = ">= 2.7" s.required_ruby_version = ">= 2.7"
s.add_dependency "faraday", "~> 1.0" s.add_dependency "faraday", ">= 1.0", "< 3"
s.add_dependency "faraday_middleware", "~> 1.0" s.add_dependency "faraday-follow_redirects", "~> 0.3"
s.add_dependency "nokogiri", "~> 1.6", ">= 1.6.8" s.add_dependency "nokogiri", "~> 1.6", ">= 1.6.8"
s.add_dependency "typhoeus", "~> 1.0" s.add_dependency "typhoeus", "~> 1.0"
s.add_dependency "valid", "~> 1.0" s.add_dependency "valid", "~> 1.0"

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "faraday" require "faraday"
require "faraday_middleware" require "faraday/follow_redirects"
module DiasporaFederation module DiasporaFederation
# A wrapper for {https://github.com/lostisland/faraday Faraday} # A wrapper for {https://github.com/lostisland/faraday Faraday}
@ -32,7 +32,8 @@ module DiasporaFederation
} }
@connection = Faraday::Connection.new(options) do |builder| @connection = Faraday::Connection.new(options) do |builder|
builder.response :follow_redirects, limit: DiasporaFederation.http_redirect_limit builder.use Faraday::FollowRedirects::Middleware, limit: DiasporaFederation.http_redirect_limit
builder.adapter Faraday.default_adapter builder.adapter Faraday.default_adapter
end end

View file

@ -33,7 +33,8 @@ module DiasporaFederation
stub_request(:get, "http://www.example.com") stub_request(:get, "http://www.example.com")
.to_return(status: 302, headers: {"Location" => "http://www.example.com"}) .to_return(status: 302, headers: {"Location" => "http://www.example.com"})
expect { HttpClient.get("http://www.example.com") }.to raise_error FaradayMiddleware::RedirectLimitReached expect { HttpClient.get("http://www.example.com") }
.to raise_error Faraday::FollowRedirects::RedirectLimitReached
end end
it "uses the gem name as User-Agent" do it "uses the gem name as User-Agent" do

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
# Use net_http in test, that's better supported by webmock
unless Rails.env.test?
require "typhoeus/adapters/faraday"
Faraday.default_adapter = :typhoeus
end