<commit_before>module Rack::Header
  class Context
    def initialize(app, headers = {})
      @app, @headers = app, headers
    end
    
    def call(env)
      status, headers, response = @app.call(env)
      @headers.each do |k,v|
        headers[k] = v
      end
      headers.delete_if { |k,v| v.nil? }
      
      [status, headers, response]
    end
  end
end<commit_msg>add support to set headers with ENV variables<commit_after>module Rack::Header
  class Context
    def initialize(app, headers = {})
      @app = app

      # Map HTTP_* environment variables to response headers
      @headers = Hash[*ENV.select {|k,v| k.start_with? 'HTTP_'}
                          .collect {|k,v| [k.sub(/^HTTP_/, ''), v]}
                          .collect {|k,v| [k.split('_').collect(&:capitalize).join('-'), v]}
                          .flatten]

      @headers = headers.merge(@headers)
    end
    
    def call(env)
      status, headers, response = @app.call(env)

      @headers.each do |k,v|
        headers[k] = v
      end
      headers.delete_if { |k,v| v.nil? }

      [status, headers, response]
    end
  end
end
{'fraction_non_alphanumeric': 0.13640389725420726, 'fraction_numerical': 0.0, 'mean_word_length': 1.9973474801061009, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3070901', 'n_tokens_mistral': 367, 'n_tokens_neox': 362, 'n_words': 93}