<commit_before>require 'set'
require 'rack/utils/environment_headers'

module Rack::Cache
  # Generic HTTP header helper methods. Provides access to headers that can be
  # included in requests and responses. This can be mixed into any object that
  # responds to #headers by returning a Hash.

  module Headers
    # Determine if any of the header names exist:
    #   if header?('Authorization', 'Cookie')
    #     ...
    #   end
    def header?(*names)
      names.any? { |name| headers.include?(name) }
    end

    # A Hash of name=value pairs that correspond to the Cache-Control header.
    # Valueless parameters (e.g., must-revalidate, no-store) have a Hash value
    # of true. This method always returns a Hash, empty if no Cache-Control
    # header is present.
    def cache_control
      @cache_control ||=
        headers['Cache-Control'].to_s.delete(' ').split(/[,;]/).inject({}) {|hash,token|
          name, value = token.split('=', 2)
          hash[name.downcase] = (value || true) unless name.empty?
          hash
        }.freeze
    end

    # Set the Cache-Control header to the values specified by the Hash. See
    # the #cache_control method for information on expected Hash structure.
    def cache_control=(hash)
      value =
        hash.collect { |key,value|
          next nil unless value
          next key if value == true
          "#{key}=#{value}"
        }.compact.join(', ')
      if value.empty?
        headers.delete('Cache-Control')
        @cache_control = {}<commit_msg>remove ";" as Cache-Control separator<commit_after>require 'set'
require 'rack/utils/environment_headers'

module Rack::Cache
  # Generic HTTP header helper methods. Provides access to headers that can be
  # included in requests and responses. This can be mixed into any object that
  # responds to #headers by returning a Hash.

  module Headers
    # Determine if any of the header names exist:
    #   if header?('Authorization', 'Cookie')
    #     ...
    #   end
    def header?(*names)
      names.any? { |name| headers.include?(name) }
    end

    # A Hash of name=value pairs that correspond to the Cache-Control header.
    # Valueless parameters (e.g., must-revalidate, no-store) have a Hash value
    # of true. This method always returns a Hash, empty if no Cache-Control
    # header is present.
    def cache_control
      @cache_control ||=
        headers['Cache-Control'].to_s.delete(' ').split(',').inject({}) {|hash,token|
          name, value = token.split('=', 2)
          hash[name.downcase] = (value || true) unless name.empty?
          hash
        }.freeze
    end

    # Set the Cache-Control header to the values specified by the Hash. See
    # the #cache_control method for information on expected Hash structure.
    def cache_control=(hash)
      value =
        hash.collect { |key,value|
          next nil unless value
          next key if value == true
          "#{key}=#{value}"
        }.compact.join(', ')
      if value.empty?
        headers.delete('Cache-Control')
        @cache_control = {}
{'fraction_non_alphanumeric': 0.10944135903299575, 'fraction_numerical': 0.0006533812479581836, 'mean_word_length': 2.5604651162790697, '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': '5276147', 'n_tokens_mistral': 866, 'n_tokens_neox': 851, 'n_words': 307}