Module: Rack::Mime

### Home Classes Methods

### In Files

- lib/rack/mime.rb

### Methods

- ::match?
- ::mime_type

### Files

- KNOWN-ISSUES

### Class/Module Index

Quicksearch

- Rack
- Rack::Auth
- Rack::Auth::AbstractHandler
- Rack::Auth::AbstractRequest
- Rack::Auth::Basic
- Rack::Auth::Basic::Request
- Rack::Auth::Digest
- Rack::Auth::Digest::MD5
- Rack::Auth::Digest::Nonce
- Rack::Auth::Digest::Params
- Rack::Auth::Digest::Request
- Rack::BodyProxy
- Rack::Builder
- Rack::Cascade
- Rack::Chunked
- Rack::Chunked::Body
- Rack::CommonLogger
- Rack::ConditionalGet
- Rack::Config
- Rack::ContentLength
- Rack::ContentType
- Rack::Deflater
- Rack::Deflater::DeflateStream
- Rack::Deflater::GzipStream
- Rack::Directory
- Rack::ETag
- Rack::File
- Rack::ForwardRequest
- Rack::Handler
- Rack::Handler::CGI
- Rack::Handler::EventedMongrel
- Rack::Handler::FastCGI
- Rack::Handler::LSWS
- Rack::Handler::Mongrel
- Rack::Handler::SCGI
- Rack::Handler::SwiftipliedMongrel
- Rack::Handler::Thin
- Rack::Handler::WEBrick
- Rack::Head
- Rack::Lint
- Rack::Lobster
- Rack::Lock
- Rack::Logger
- Rack::MethodOverride
- Rack::Mime
- Rack::MockRequest
- Rack::MockRequest::FatalWarner
- Rack::MockRequest::FatalWarning
- Rack::MockResponse
- Rack::Multipart
- Rack::Multipart::Generator
- Rack::Multipart::Parser
- Rack::Multipart::UploadedFile
- Rack::NullLogger
- Rack::Recursive
- Rack::Reloader
- Rack::Reloader::Stat
- Rack::Request
- Rack::Response
- Rack::Response::Helpers
- Rack::RewindableInput
- Rack::RewindableInput::Tempfile
- Rack::Runtime
- Rack::Sendfile
- Rack::Server
- Rack::Server::Options
- Rack::Session
- Rack::Session::Abstract
- Rack::Session::Abstract::ID
- Rack::Session::Abstract::SessionHash
- Rack::Session::Cookie
- Rack::Session::Cookie::Base64
- Rack::Session::Cookie::Base64::JSON
- Rack::Session::Cookie::Base64::Marshal
- Rack::Session::Cookie::Identity
- Rack::Session::Cookie::Reverse
- Rack::Session::Memcache
- Rack::Session::Pool
- Rack::ShowExceptions
- Rack::ShowStatus
- Rack::Static
- Rack::URLMap
- Rack::Utils
- Rack::Utils::Context
- Rack::Utils::HeaderHash
- Rack::Utils::KeySpaceConstrainedParams
- Rack::Utils::Multipart
- Rack::Utils::OkJson
- Rack::Utils::OkJson::Error
- Rack::Utils::OkJson::Utf8Error
- FCGI
- FCGI::Stream
- Object

No matching classes.

# Rack::Mime

### Constants

MIME_TYPES

  List of most common mime-types, selected various sources according to their usefulness in a webserving scope for Ruby users.

  To amend this list with your local mime.types list you can use:

      require 'webrick/httputils'
      list = WEBrick::HTTPUtils.load_mime_types('/etc/mime.types')
      Rack::Mime::MIME_TYPES.merge!(list)

  N.B. On Ubuntu the mime.types file does not include the leading period, so users may need to modify the data before merging into the hash.

  To add the list mongrel provides, use:

      require 'mongrel/handlers'
      Rack::Mime::MIME_TYPES.merge!(Mongrel::DirHandler::MIME_TYPES)

### Public Class Methods

match?(value, matcher) click to toggle source

Returns true if the given value is a mime match for the given mime match specification, false otherwise.

    Rack::Mime.match?('text/html', 'text/*') => true
    Rack::Mime.match?('text/plain', '*') => true
    Rack::Mime.match?('text/html', 'application/json') => false

    # File lib/rack/mime.rb, line 28
    def match?(value, matcher)
      v1, v2 = value.split('/', 2)
      m1, m2 = matcher.split('/', 2)

      if m1 == '*'
        if m2.nil? || m2 == '*'
          return true
        elsif m2 == v2
          return true
        else
          return false
        end
      end

      return false if v1 != m1

      return true if m2.nil? || m2 == '*'

      m2 == v2
    end

mime_type(ext, fallback='application/octet-stream') click to toggle source

Returns String with mime type if found, otherwise use `fallback`. `ext` should be filename extension in the '.ext' format that

    File.extname(file) returns.

`fallback` may be any object

Also see the documentation for MIME_TYPES

Usage:

    Rack::Mime.mime_type('.foo')

This is a shortcut for:

    Rack::Mime::MIME_TYPES.fetch('.foo', 'application/octet-stream')

    # File lib/rack/mime.rb, line 16
    def mime_type(ext, fallback='application/octet-stream')
      MIME_TYPES.fetch(ext.to_s.downcase, fallback)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.