<commit_before>module Rack
  class Metadata

    def initialize(app, options = {})
      @app = app
    end

    def call(env)
      env['rack.metadata'] = {}
      status, headers, response = @app.call(env)

      if headers['Content-Type'].to_s.include?('text/html') # Only update HTML bodies
        if env['rack.metadata']
          env['rack.metadata'].each do |k, v|
            response.each do |part|
              if part.rindex('</head>')
                part.gsub!('</head>', message(k, v) + '</head>')
                headers['Content-Length'] = (headers['Content-Length'].to_i + message.length).to_s
              end
            end
          end
      end

      [status, headers, response]
    end

    private

    def message(name, content)
      %{<meta name="#{name}" content="#{content}" />}
    end

  end
end<commit_msg>fix content length adjustment<commit_after>module Rack
  class Metadata

    def initialize(app, options = {})
      @app = app
    end

    def call(env)
      env['rack.metadata'] = {}
      status, headers, response = @app.call(env)

      if headers['Content-Type'].to_s.include?('text/html') # Only update HTML bodies
        if env['rack.metadata']
          env['rack.metadata'].each do |k, v|
            response.each do |part|
              if part.rindex('</head>')
                tag = message(k, v)
                part.gsub!('</head>', tag + '</head>')
                headers['Content-Length'] = (headers['Content-Length'].to_i + tag.length).to_s
              end
            end
          end
      end

      [status, headers, response]
    end

    private

    def message(name, content)
      %{<meta name="#{name}" content="#{content}" />}
    end

  end
end
{'fraction_non_alphanumeric': 0.14907192575406034, 'fraction_numerical': 0.0, 'mean_word_length': 1.9286926994906621, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4512734', 'n_tokens_mistral': 531, 'n_tokens_neox': 508, 'n_words': 122}