Sha256: 70ea718e05eb1f6fa893f326dd6c09be3536de746c54dc2953564049e353bafd

Contents?: true

Size: 996 Bytes

Versions: 6

Compression:

Stored size: 996 Bytes

Contents

module Rack::Accept
  # Represents an HTTP Accept-Encoding header according to the HTTP 1.1
  # specification, and provides several convenience methods for determining
  # acceptable content encodings.
  #
  # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
  class Encoding
    include Header

    # The name of this header.
    def name
      'Accept-Encoding'
    end

    # Determines the quality factor (qvalue) of the given +encoding+.
    def qvalue(encoding)
      m = matches(encoding)
      if m.empty?
        encoding == 'identity' ? 1 : 0
      else
        normalize_qvalue(@qvalues[m.first])
      end
    end

    # Returns an array of encodings from this header that match the given
    # +encoding+, ordered by precedence.
    def matches(encoding)
      values.select {|v|
        v == encoding || v == '*'
      }.sort {|a, b|
        # "*" gets least precedence, any others should be equal.
        a == '*' ? 1 : (b == '*' ? -1 : 0)
      }
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rack-accept-0.4.5/lib/rack/accept/encoding.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rack-accept-0.4.5/lib/rack/accept/encoding.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/rack-accept-0.4.5/lib/rack/accept/encoding.rb
rack-accept-0.4.5 lib/rack/accept/encoding.rb
rack-accept-0.4.4 lib/rack/accept/encoding.rb
rack-accept-0.4.3 lib/rack/accept/encoding.rb