Sha256: f40aa8f55e6b9e513a849e7d3da645caf20210687855766076f062b24015ef74
Contents?: true
Size: 596 Bytes
Versions: 19
Compression:
Stored size: 596 Bytes
Contents
# frozen_string_literal: true 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) m = str.to_s[MIME_TYPE_RE, 1] m && m.strip.downcase end # :nodoc: def charset(str) m = str.to_s[CHARSET_RE, 1] m && m.strip.delete('"') end end end end
Version data entries
19 entries across 19 versions & 1 rubygems