class Excon::HyperMedia::Middleware

Middleware

This middleware sets the `hypermedia` datum to `true`, if the returned `Content-Type` header contains `hal+json`.

If the `hypermedia` attribute is already set for the connection, it will be left alone by this middleware.

Public Instance Methods

request_call(datum) click to toggle source
Calls superclass method
# File lib/excon/hypermedia/middleware.rb, line 27
def request_call(datum)
  # 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
response_call(datum) click to toggle source
Calls superclass method
# File lib/excon/hypermedia/middleware.rb, line 38
def response_call(datum)
  return super unless (headers = datum.dig(:response, :headers))
  return super unless (match = headers.find { |k, v| k.downcase == 'content-type' })
  content_type = match[1].to_s

  datum[:response][:hypermedia] = if datum[:hypermedia].nil?
    content_type.include?('hal+json')
  else
    datum[:hypermedia]
  end

  super
end