lib/coach/request_serializer.rb in coach-2.0.0 vs lib/coach/request_serializer.rb in coach-2.1.0

- old
+ new

@@ -1,9 +1,14 @@ # frozen_string_literal: true module Coach class RequestSerializer + # Rack specs dictate that CONTENT_TYPE and CONTENT_LENGTH + # are not prefixed with HTTP_. + # See https://rubydoc.info/github/rack/rack/master/file/SPEC + RACK_UNPREFIXED_HEADERS = %w[CONTENT_TYPE CONTENT_LENGTH].freeze + def self.header_rules @header_rules ||= {} end # Sets global rules on how to sanitize headers. An optional block can be supplied @@ -55,12 +60,16 @@ "unknown" end def filtered_headers header_value_pairs = @request.filtered_env.map do |key, value| - next unless key =~ /^HTTP_/ + key = if RACK_UNPREFIXED_HEADERS.include?(key) + "http_#{key.downcase}" + elsif key =~ /^HTTP_/ + key.downcase + end - [key.downcase, self.class.apply_header_rule(key.downcase, value)] + [key, self.class.apply_header_rule(key, value)] if key end.compact Hash[header_value_pairs] end end