class Rack::Test::Cookie

:nodoc:
API and behavior of this class can change at any time.
Represents individual cookies in the cookie jar. This is considered private

def <=>(other)

Order cookies by name, path, and domain.
def <=>(other)
  [name, path, domain.reverse] <=> [other.name, other.path, other.domain.reverse]
end

def default_uri

The default URI to use for the cookie, including just the host.
def default_uri
  URI.parse('//' + @default_host + '/')
end

def domain

The explicit or implicit domain for the cookie.
def domain
  @options['domain']
end

def empty?

Whether the cookie has a value.
def empty?
  @value.nil? || @value.empty?
end

def expired?

Whether the cookie is currently expired.
def expired?
  expires && expires < Time.now
end

def expires

A Time value for when the cookie expires, if the expires option is set.
def expires
  Time.parse(@options['expires']) if @options['expires']
end

def http_only?

a javascript API.
Whether the cookie has the httponly flag, indicating it is not available via
def http_only?
  @options.key?('HttpOnly') || @options.key?('httponly')
end

def initialize(raw, uri = nil, default_host = DEFAULT_HOST)

def initialize(raw, uri = nil, default_host = DEFAULT_HOST)
  @default_host = default_host
  uri ||= default_uri
  # separate the name / value pair from the cookie options
  @raw, options = raw.split(/[;,] */n, 2)
  @name, @value = parse_query(@raw, ';').to_a.first
  @options = parse_query(options, ';')
  if domain = @options['domain']
    @exact_domain_match = false
    domain[0] = '' if domain[0] == '.'
  else
    # If the domain attribute is not present in the cookie,
    # the domain must match exactly.
    @exact_domain_match = true
    @options['domain'] = (uri.host || default_host)
  end
  # Set the path for the cookie to the directory containing
  # the request if it isn't set.
  @options['path'] ||= uri.path.sub(/\/[^\/]*\Z/, '')
end

def matches?(uri)

Cookies that do not match the URI will not be sent in requests to the URI.
def matches?(uri)
  !expired? && valid?(uri) && uri.path.start_with?(path)
end

def path

The explicit or implicit path for the cookie.
def path
  ([*@options['path']].first.split(',').first || '/').strip
end

def replaces?(other)

Wether the given cookie can replace the current cookie in the cookie jar.
def replaces?(other)
  [name.downcase, domain, path] == [other.name.downcase, other.domain, other.path]
end

def secure?

an encrypted connection.
Whether the cookie has the secure flag, indicating it can only be sent over
def secure?
  @options.key?('secure')
end

def to_h

A hash of cookie options, including the cookie value, but excluding the cookie name.
def to_h
  @options.merge(
    'value'    => @value,
    'HttpOnly' => http_only?,
    'secure'   => secure?
  )
end

def valid?(uri)

Whether the cookie is valid for the given URI.
def valid?(uri)
  uri ||= default_uri
  uri.host = @default_host if uri.host.nil?
  real_domain = domain =~ /^\./ ? domain[1..-1] : domain
  !!((!secure? || (secure? && uri.scheme == 'https')) &&
    uri.host =~ Regexp.new("#{'^' if @exact_domain_match}#{Regexp.escape(real_domain)}$", Regexp::IGNORECASE))
end