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

Don't register the request/response json middleware for Faraday 1.10+ #288

Merged
merged 4 commits into from
Sep 23, 2024
Merged
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
9 changes: 7 additions & 2 deletions lib/faraday_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ module FaradayMiddleware
Faraday::Request.register_middleware \
oauth: -> { OAuth },
oauth2: -> { OAuth2 },
json: -> { EncodeJson },
method_override: -> { MethodOverride }

Faraday::Response.register_middleware \
mashify: -> { Mashify },
rashify: -> { Rashify },
json: -> { ParseJson },
json_fix: -> { ParseJson::MimeTypeFix },
xml: -> { ParseXml },
marshal: -> { ParseMarshal },
Expand All @@ -46,6 +44,13 @@ module FaradayMiddleware
Faraday::Middleware.register_middleware \
instrumentation: -> { Instrumentation },
gzip: -> { Gzip }

# The request/reponse JSON middleware is included in Faraday since
# version 1.10.0, so we only register the middleware if it's not already.
if Gem::Version.new(Faraday::VERSION) < Gem::Version.new('1.10.0')
Faraday::Request.register_middleware(json: -> { EncodeJson })
Faraday::Response.register_middleware(json: -> { ParseJson })
end
end
end

Expand Down