class HTTPClient::WebAgentSaver

Constants

DOMAIN
HTTP_ONLY
PATH
SECURE
USE

Private Class Methods

flag(cookie) click to toggle source
# File lib/httpclient/cookie.rb, line 157
def self.flag(cookie)
  flg = 0
  flg += USE # not used
  flg += SECURE  if cookie.secure?
  flg += DOMAIN  if cookie.for_domain?
  flg += HTTP_ONLY  if cookie.httponly?
  flg += PATH  if cookie.path # not used
  flg
end
set_flag(cookie, flag) click to toggle source
# File lib/httpclient/cookie.rb, line 167
def self.set_flag(cookie, flag)
  cookie.secure = true if flag & SECURE > 0
  cookie.for_domain = true if flag & DOMAIN > 0
  cookie.httponly = true if flag & HTTP_ONLY > 0
end

Public Instance Methods

default_options() click to toggle source

no option

# File lib/httpclient/cookie.rb, line 91
def default_options
  {}
end
load(io, jar) click to toggle source

same as HTTP::CookieJar::CookiestxtSaver

# File lib/httpclient/cookie.rb, line 104
def load(io, jar)
  io.each_line { |line|
    cookie = parse_record(line) and jar.add(cookie)
  }
end
save(io, jar) click to toggle source

same as HTTP::CookieJar::CookiestxtSaver

# File lib/httpclient/cookie.rb, line 96
def save(io, jar)
  jar.each { |cookie|
    next if !@session && cookie.session?
    io.print cookie_to_record(cookie)
  }
end

Private Instance Methods

parse_record(line) click to toggle source
# File lib/httpclient/cookie.rb, line 124
def parse_record(line)
  return nil if /\A#/ =~ line
  col = line.chomp.split(/\t/)

  origin = col[0]
  name = col[1]
  value = col[2]
  value.chomp!
  if col[3].empty? or col[3] == '0'
    expires = nil
  else
    expires = Time.at(col[3].to_i)
    return nil if expires < Time.now
  end
  domain = col[4]
  path = col[5]

  cookie = WebAgent::Cookie.new(name, value,
    :origin => origin,
    :domain => domain,
    :path => path,
    :expires => expires
  )
  self.class.set_flag(cookie, col[6].to_i)
  cookie
end