Skip to content

Commit

Permalink
Register json middleware correctly (#1331)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5366029)
  • Loading branch information
mollerhoj authored and iMacTia committed Feb 16, 2022
1 parent be535c3 commit 73cd48c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/faraday/request.rb
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/faraday/request/json.rb
Expand Up @@ -51,3 +51,5 @@ def request_type(env)
end
end
end

Faraday::Request.register_middleware(json: Faraday::Request::Json)
3 changes: 2 additions & 1 deletion lib/faraday/response.rb
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/faraday/response/json.rb
Expand Up @@ -50,3 +50,5 @@ def response_type(env)
end
end
end

Faraday::Response.register_middleware(json: Faraday::Response::Json)

0 comments on commit 73cd48c

Please sign in to comment.