Sha256: ce619bc66ec9094f6dbd366a48f6e3cc769f858d8a47bd4a70ad0d77f6e44885

Contents?: true

Size: 597 Bytes

Versions: 44

Compression:

Stored size: 597 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

44 entries across 44 versions & 1 rubygems

Version Path
http-2.0.0 lib/http/content_type.rb
http-2.0.0.pre lib/http/content_type.rb
http-1.0.4 lib/http/content_type.rb
http-0.9.9 lib/http/content_type.rb
http-1.0.3 lib/http/content_type.rb
http-1.0.2 lib/http/content_type.rb
http-1.0.1 lib/http/content_type.rb
http-1.0.0 lib/http/content_type.rb
http-1.0.0.pre6 lib/http/content_type.rb
http-1.0.0.pre5 lib/http/content_type.rb
http-1.0.0.pre4 lib/http/content_type.rb
http-1.0.0.pre3 lib/http/content_type.rb
http-1.0.0.pre2 lib/http/content_type.rb
http-1.0.0.pre1 lib/http/content_type.rb
http-0.9.8 lib/http/content_type.rb
http-0.9.7 lib/http/content_type.rb
http-0.9.6 lib/http/content_type.rb
http-0.9.5 lib/http/content_type.rb
http-0.9.4 lib/http/content_type.rb
http-0.9.3 lib/http/content_type.rb