lib/eac_envs/http/response.rb in eac_envs-http-0.2.0 vs lib/eac_envs/http/response.rb in eac_envs-http-0.3.0

- old
+ new

@@ -7,10 +7,11 @@ require 'json' module EacEnvs module Http class Response < ::StandardError + COMMON_HEADERS = %w[Content-Type].freeze HEADER_LINE_PARSER = /\A([^:]+):(.*)\z/.to_parser do |m| [m[1].strip, m[2].strip] end # https://www.w3.org/wiki/LinkHeader @@ -52,14 +53,13 @@ def header(name) hash_search(headers, name) end + # @return [Hash<String, String>] def headers - performed.header_str.each_line.map(&:strip)[1..-1].reject(&:blank?) - .map { |header_line| HEADER_LINE_PARSER.parse!(header_line) } - .to_h + performed.headers.to_hash end def link(rel) hash_search(links, rel) end @@ -82,9 +82,15 @@ delegate :url, to: :request def to_s "URL: #{url}\nStatus: #{status}\nBody:\n\n#{body_str}" + end + + COMMON_HEADERS.each do |header_key| + define_method header_key.underscore do + header(header_key) + end end private def body_data_from_application_json