Skip to content

Commit

Permalink
Don't register the request/response json middleware for Faraday 1.10+ (
Browse files Browse the repository at this point in the history
…#288)

Faraday 1.10 ships with an out-of-the-box JSON middleware, so we want to to default to that one rather than the faraday_middleware one.

Co-authored-by: Olle Jonsson <[email protected]>
  • Loading branch information
iMacTia and olleolleolle authored Sep 23, 2024
1 parent 8786fb6 commit 88ed602
Showing 1 changed file with 7 additions and 2 deletions.
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

0 comments on commit 88ed602

Please sign in to comment.