From 73cd48c248f0e1c6cedc3762020b55965de7cccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Dahl=20M=C3=B8llerh=C3=B8j?= Date: Fri, 8 Oct 2021 13:38:11 +0100 Subject: [PATCH] Register json middleware correctly (#1331) (cherry picked from commit 5366029282968d59980a182258f8c2b0212721c8) --- lib/faraday/request.rb | 3 ++- lib/faraday/request/json.rb | 2 ++ lib/faraday/response.rb | 3 ++- lib/faraday/response/json.rb | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/faraday/request.rb b/lib/faraday/request.rb index 791fbf83e..19cae6f2a 100644 --- a/lib/faraday/request.rb +++ b/lib/faraday/request.rb @@ -44,7 +44,8 @@ class Request < Struct.new( :TokenAuthentication, 'token_authentication' ], - instrumentation: [:Instrumentation, 'instrumentation'] + instrumentation: [:Instrumentation, 'instrumentation'], + json: [:Json, 'json'] # @param request_method [String] # @yield [request] for block customization, if block given diff --git a/lib/faraday/request/json.rb b/lib/faraday/request/json.rb index a17a4dd06..fa219c49d 100644 --- a/lib/faraday/request/json.rb +++ b/lib/faraday/request/json.rb @@ -51,3 +51,5 @@ def request_type(env) end end end + +Faraday::Request.register_middleware(json: Faraday::Request::Json) diff --git a/lib/faraday/response.rb b/lib/faraday/response.rb index 402b5f089..d58869849 100644 --- a/lib/faraday/response.rb +++ b/lib/faraday/response.rb @@ -22,7 +22,8 @@ def on_complete(env) register_middleware File.expand_path('response', __dir__), raise_error: [:RaiseError, 'raise_error'], - logger: [:Logger, 'logger'] + logger: [:Logger, 'logger'], + json: [:Json, 'json'] def initialize(env = nil) @env = Env.from(env) if env diff --git a/lib/faraday/response/json.rb b/lib/faraday/response/json.rb index 19fa72047..399b7f351 100644 --- a/lib/faraday/response/json.rb +++ b/lib/faraday/response/json.rb @@ -50,3 +50,5 @@ def response_type(env) end end end + +Faraday::Response.register_middleware(json: Faraday::Response::Json)