module MIME::Types

Overview

MIME::Types is a registry of MIME types. It is both a class (created with MIME::Types.new) and a default registry (loaded automatically or through interactions with MIME::Types.[]``,MIME::Types.for_filename,MIME::Types.for_extension`).

The Default mime-types Registry

The default mime-types registry is loaded automatically when the library is required (require "mime/types").

Usage

require "mime/types"

plaintext = MIME::Types["text/plain"]
print plaintext.media_type # => "text'
print plaintext.sub_type   # => "plain"

puts plaintext.extensions.join(" ") # => "asc txt c cc h hh cpp"

puts plaintext.encoding                    # => 8bit
puts plaintext.binary?                     # => false
puts plaintext.ascii?                      # => true
puts plaintext.obsolete?                   # => false
puts plaintext.registered?                 # => true
puts plaintext == "text/plain"             # => true
puts MIME::Type.simplified("x-appl/x-zip") # => "appl/zip"

Extended Modules

Defined in:

mime/types.cr
mime/types/list.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.[](content_type : String, complete = false, registered = false) #

Returns a list of MIME::Type objects, which may be empty. The optional flag parameters are :complete (finds only complete MIME::Type objects) and :registered (finds only MIME::Types that are registered). It is possible for multiple matches to be returned for either type (in the example below, 'text/plain' returns two values -- one for the general case, and one for VMS systems).

MIME::Types["text/plain"].each { |t| puts t.to_a.join(", ") }

MIME::Types[/^image/, :complete => true].each do |t|
  puts t.to_a.join(", ")
end

[View source]
def self.[](content_type : Regex, complete = false, registered = false) #

[View source]
def self.inspect(io) #

[View source]
def self.register(*args) #

Registers a new MIME::Type, delegating to MIME::Type.new


[View source]
def self.registry #

Returns a list of all registered MIME::Types


[View source]
def self.to_s(io) #

[View source]

Instance Method Detail

def for_extension(ext : String) #

Returns the type for a extension string


[View source]
def type_for(file : File) #

Returns the type for a File


[View source]
def type_for(filename : String) #

Returns the type for a filename string


[View source]
def type_for(request : HTTP::Request) #

Returns the types for an HTTP::Request Content-Type header.


[View source]
def type_for(response : HTTP::Client::Response) #

Returns the types for an HTTP::Client::Response Content-Type header.


[View source]
def type_for_accept(request : HTTP::Request) #

Returns the types for an HTTP::Request Accept header.


[View source]