Slide 25
Slide 25 text
def parse(header)
directives = {}
header.delete(' ').split(',').each do |part|
next if part.empty?
name, value = part.split('=', 2)
directives[name.downcase] = (value || true) unless name.empty?
end
directives
end
# Internal: Parses the Cache Control string to a Hash.
# Existing whitespace will be removed and the string is split on commas.
# For each part everything before a '=' will be treated as the key
# and the exceeding will be treated as the value. If only the key is
# present then the assigned value will default to true.
#
# Examples:
# parse("max-age=600")
# # => { "max-age" => "600" }
#
# parse("max-age")
# # => { "max-age" => true }
#
# Returns a Hash.