Sha256: 68ea3e2e7324bea5682181da2842deeb0ca1a6f9a164ad81b31bb551bce26861
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true module Excon module HyperMedia module Middlewares # HypertextCachePattern # # This middleware handles hcp-enabled requests. # # @see: https://tools.ietf.org/html/draft-kelly-json-hal-06#section-8.3 # class HypertextCachePattern < Excon::Middleware::Base attr_reader :datum def request_call(datum) @datum = datum return super unless datum[:hcp] == true && datum[:method] == :get && resource datum[:response] = { body: resource.to_json, hcp: true, headers: content_type_header, remote_ip: '127.0.0.1', status: 200 } super end private def resource @resource ||= embedded.find { |name, _| name == relation_name }.to_a[1] end def relation_name datum.dig(:hcp_params, :relation) end def embedded datum.dig(:hcp_params, :embedded).to_h end def content_type_header return {} unless (header = datum.dig(:hcp_params, :content_type)) { 'Content-Type' => header } end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
excon-hypermedia-0.5.2 | lib/excon/hypermedia/middlewares/hypertext_cache_pattern.rb |