Sha256: d71f8765e6e25f23c4b0db6994996cb9027adaa0e19b884225dfe76cc7662564
Contents?: true
Size: 595 Bytes
Versions: 11
Compression:
Stored size: 595 Bytes
Contents
module HTTP ContentType = Struct.new(:mime_type, :charset) do MIME_TYPE_RE = %r{^([^/]+/[^;]+)(?:$|;)} CHARSET_RE = /;\s*charset=([^;]+)/i class << self # Parse string and return ContentType struct def parse(str) new mime_type(str), charset(str) end private # :nodoc: def mime_type(str) md = str.to_s.match MIME_TYPE_RE md && md[1].to_s.strip.downcase end # :nodoc: def charset(str) md = str.to_s.match CHARSET_RE md && md[1].to_s.strip.gsub(/^"|"$/, '') end end end end
Version data entries
11 entries across 11 versions & 1 rubygems