lib/contrast/agent/response.rb in contrast-agent-3.14.0 vs lib/contrast/agent/response.rb in contrast-agent-3.15.0

- old
+ new

@@ -42,18 +42,13 @@ # B/c the response can change, we can't memoize this :( def dtm context_response = Contrast::Api::Dtm::HttpResponse.new context_response.response_code = response_code.to_i headers&.each_pair do |key, value| - k = Contrast::Utils::StringUtils.force_utf8(key) - v = Contrast::Utils::StringUtils.force_utf8(value) - context_response.response_headers[k] = v + append_pair(context_response.normalized_response_headers, key, value) end - context_response.parsed_response_headers = true - context_response.response_body_binary = Contrast::Utils::StringUtils.force_utf8(body) - context_response.parsed_response_body = false doc_type = document_type context_response.document_type = doc_type if doc_type context_response @@ -94,9 +89,25 @@ body_content = @is_array ? rack_response[2] : rack_response.body extract_body(body_content) end private + + # From the dtm for normalized_response_headers: + # Key is UPPERCASE_UNDERSCORE + # + # Example: Content-Type: text/html; charset=utf-8 + # "CONTENT_TYPE" => Content-Type,["text/html; charset=utf8"] + def append_pair map, key, value + return unless key && value + return if value.is_a?(Hash) + + safe_key = Contrast::Utils::StringUtils.force_utf8(key) + hash_key = Contrast::Utils::StringUtils.normalized_key(safe_key) + map[hash_key] ||= Contrast::Api::Dtm::Pair.new + map[hash_key].key = safe_key + map[hash_key].values << Contrast::Utils::StringUtils.force_utf8(value) + end HTTP_PREFIX = /^[Hh][Tt][Tt][Pp][_-]/i.cs__freeze # Given some holder of the content of the response's body, extract that # content and return it as a String