lib/excon/hypermedia/middleware.rb in excon-hypermedia-0.4.3 vs lib/excon/hypermedia/middleware.rb in excon-hypermedia-0.5.0
- old
+ new
@@ -1,7 +1,9 @@
# frozen_string_literal: true
+require 'backport_dig' if RUBY_VERSION < '2.3'
+
Excon.defaults[:middlewares].delete(Excon::Addressable::Middleware)
Excon.defaults[:middlewares].unshift(Excon::Addressable::Middleware)
module Excon
module HyperMedia
@@ -12,9 +14,15 @@
#
# If the `hypermedia` attribute is already set for the connection, it
# will be left alone by this middleware.
#
class Middleware < Excon::Middleware::Base
+ def request_call(datum)
+ orig_stack = @stack
+ @stack = Excon::HyperMedia::Middlewares::HypertextCachePattern.new(orig_stack)
+ super
+ end
+
def response_call(datum)
return super unless (content_type = datum.dig(:response, :headers, 'Content-Type').to_s)
datum[:response][:hypermedia] = if datum[:hypermedia].nil?
content_type.include?('hal+json')