lib/timber/util/http_event.rb in timber-2.1.0.rc3 vs lib/timber/util/http_event.rb in timber-2.1.0.rc4

- old
+ new

@@ -31,31 +31,19 @@ end end # Normalizes headers to: # - # 1. Ensure the value is UTF8, this will otherwise throw errors upon capturing. + # 1. Only select values that are UTF8, otherwise they will throw errors when serializing. # 2. Sanitize sensitive headers such as `Authorization` or custom headers specified in def normalize_headers(headers) if headers.is_a?(::Hash) h = headers.each_with_object({}) do |(k, v), h| - # Force the header into a valid UTF-8 string, otherwise we will encounter - # encoding issues when we serialize this data. Moreoever, if the - # data is already valid UTF-8 we don't pay a penalty. - # - # Note: we compare the class name because... - # - # string = 'my string'.force_encoding('ASCII-8BIT') - # string.is_a?(String) => false - # string.class => String - # string.class == String => false - # string.class.name == "String" => true - # - # ¯\_(ツ)_/¯ - if v.class.name == STRING_CLASS_NAME - h[k] = Timber::Util::String.normalize_to_utf8(v) - else - h[k] = v + if v + v = v.to_s + if [Encoding::UTF_8, Encoding::US_ASCII].include?(v.encoding) + h[k] = v + end end end keys_to_sanitize = HEADERS_TO_SANITIZE + (Config.instance.http_header_filters || []) Util::Hash.sanitize(h, keys_to_sanitize) \ No newline at end of file