Parent

Included Modules

WebAgent::Cookie

Attributes

discard[W]
domain[RW]
domain_orig[W]
expires[RW]
http_only[W]
name[RW]
override[W]
path[RW]
path_orig[W]
secure[W]
url[RW]
use[W]
value[RW]

Public Class Methods

new() click to toggle source
# File lib/httpclient/cookie.rb, line 69
def initialize
  @name = @value = @domain = @path = nil
  @expires = nil
  @url = nil
  @use = @secure = @http_only = @discard = @domain_orig = @path_orig = @override = nil
end

Public Instance Methods

discard?() click to toggle source
# File lib/httpclient/cookie.rb, line 76
def discard?
  @discard
end
domain_orig?() click to toggle source
# File lib/httpclient/cookie.rb, line 92
def domain_orig?
  @domain_orig
end
flag() click to toggle source
# File lib/httpclient/cookie.rb, line 104
def flag
  flg = 0
  flg += USE  if @use
  flg += SECURE  if @secure
  flg += HTTP_ONLY  if @http_only
  flg += DOMAIN  if @domain_orig
  flg += PATH  if @path_orig
  flg += DISCARD if @discard
  flg += OVERRIDE if @override
  flg
end
http_only?() click to toggle source
# File lib/httpclient/cookie.rb, line 88
def http_only?
  @http_only
end
join_quotedstr(array, sep) click to toggle source
# File lib/httpclient/cookie.rb, line 139
def join_quotedstr(array, sep)
  ret = Array.new
  old_elem = nil
  array.each{|elem|
    if (elem.scan(/"/).length % 2) == 0
      if old_elem
        old_elem << sep << elem
      else
        ret << elem
        old_elem = nil
      end  
    else
      if old_elem
        old_elem << sep << elem
        ret << old_elem
        old_elem = nil
      else
        old_elem = elem.dup
      end
    end
  }
  ret
end
match?(url) click to toggle source
# File lib/httpclient/cookie.rb, line 127
def match?(url)
  domainname = url.host
  if (!domainname ||
      !domain_match(domainname, @domain) ||
      (@path && !head_match?(@path, url.path.empty? ? '/' : url.path)) ||
      (@secure && (url.scheme != 'https')) )
    return false
  else
    return true
  end
end
override?() click to toggle source
# File lib/httpclient/cookie.rb, line 100
def override?
  @override
end
parse(str, url) click to toggle source
# File lib/httpclient/cookie.rb, line 163
def parse(str, url)
  @url = url
  # TODO: should not depend on join_quotedstr. scan with escape like CSV.
  cookie_elem = str.split(/;/)
  cookie_elem = join_quotedstr(cookie_elem, ';')
  cookie_elem -= [""] # del empty elements, a cookie might included ";;"
  first_elem = cookie_elem.shift
  if first_elem !~ /([^=]*)(\=(.*))?/
    return
    ## raise ArgumentError 'invalid cookie value'
  end
  @name = $1.strip
  @value = normalize_cookie_value($3)
  cookie_elem.each{|pair|
    key, value = pair.split(/=/, 2)  ## value may nil
    key.strip!
    value = normalize_cookie_value(value)
    case key.downcase
    when 'domain'
      @domain = value
    when 'expires'
      @expires = nil
      begin
        @expires = Time.parse(value).gmtime if value
      rescue ArgumentError
      end
    when 'path'
      @path = value
    when 'secure'
      @secure = true  ## value may nil, but must 'true'.
    when 'httponly'
      @http_only = true  ## value may nil, but must 'true'.
    else
      ## ignore
    end
  }
end
path_orig?() click to toggle source
# File lib/httpclient/cookie.rb, line 96
def path_orig?
  @path_orig
end
secure?() click to toggle source
# File lib/httpclient/cookie.rb, line 84
def secure?
  @secure
end
set_flag(flag) click to toggle source
# File lib/httpclient/cookie.rb, line 116
def set_flag(flag)
  flag = flag.to_i
  @use = true      if flag & USE > 0
  @secure = true   if flag & SECURE > 0
  @http_only = true   if flag & HTTP_ONLY > 0
  @domain_orig = true if flag & DOMAIN > 0
  @path_orig = true if flag & PATH > 0
  @discard  = true if flag & DISCARD > 0
  @override = true if flag & OVERRIDE > 0
end
use?() click to toggle source
# File lib/httpclient/cookie.rb, line 80
def use?
  @use
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.