lib/excon/hypermedia/middleware.rb in excon-hypermedia-0.5.2 vs lib/excon/hypermedia/middleware.rb in excon-hypermedia-0.5.3

- old
+ new

@@ -15,11 +15,16 @@ # 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) + # if `hcp` is enabled, insert the `HypertextCachePattern` middleware in + # the middleware stack right after this one. + if datum[:hcp] + orig_stack = @stack + @stack = Excon::HyperMedia::Middlewares::HypertextCachePattern.new(orig_stack) + end + super end def response_call(datum) return super unless (content_type = datum.dig(:response, :headers, 'Content-Type').to_s)