Parent

Included Modules

Files

Rack::Accept::MediaType

Represents an HTTP Accept header according to the HTTP 1.1 specification, and provides several convenience methods for determining acceptable media types.

www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1

Public Class Methods

new(header) click to toggle source
# File lib/rack/accept/media_type.rb, line 42
def initialize(header)
  # Strip accept-extension for now. We may want to do something with this
  # later if people actually start to use it.
  header = header.to_s.split(/,\s*/).map {|part|
    part.sub(/(;\s*q\s*=\s*[\d.]+).*$/, '\1')
  }.join(', ')

  super(header)
end

Public Instance Methods

matches(media_type) click to toggle source

Returns an array of media types from this header that match the given media_type, ordered by precedence.

# File lib/rack/accept/media_type.rb, line 25
def matches(media_type)
  type, subtype, params = parse_media_type(media_type)
  values.select {|v|
    if v == media_type || v == '*/*'
      true
    else
      t, s, p = parse_media_type(v)
      t == type && (s == '*' || s == subtype) && (p == '' || params_match?(params, p))
    end
  }.sort_by {|v|
    # Most specific gets precedence.
    v.length
  }.reverse
end
name() click to toggle source

The name of this header.

# File lib/rack/accept/media_type.rb, line 11
def name
  'Accept'
end
qvalue(media_type) click to toggle source

Determines the quality factor (qvalue) of the given media_type.

# File lib/rack/accept/media_type.rb, line 16
def qvalue(media_type)
  return 1 if @qvalues.empty?
  m = matches(media_type)
  return 0 if m.empty?
  normalize_qvalue(@qvalues[m.first])
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.