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.crmime/types/list.cr
Class Method Summary
-
.[](content_type : String, complete = false, registered = false)
Returns a list of MIME::Type objects, which may be empty.
- .[](content_type : Regex, complete = false, registered = false)
- .inspect(io)
-
.register(*args)
Registers a new
MIME::Type
, delegating toMIME::Type.new
-
.registry
Returns a list of all registered MIME::Types
- .to_s(io)
Instance Method Summary
-
#for_extension(ext : String)
Returns the type for a extension string
-
#type_for(file : File)
Returns the type for a File
-
#type_for(filename : String)
Returns the type for a filename string
-
#type_for(request : HTTP::Request)
Returns the types for an
HTTP::Request
Content-Type header. -
#type_for(response : HTTP::Client::Response)
Returns the types for an
HTTP::Client::Response
Content-Type header. -
#type_for_accept(request : HTTP::Request)
Returns the types for an
HTTP::Request
Accept header.
Class Method Detail
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
Instance Method Detail
Returns the types for an HTTP::Client::Response
Content-Type header.
Returns the types for an HTTP::Request
Accept header.