def each(uri = nil, &block)
now = Time.now
if uri
thost = DomainName.new(uri.host)
tpath = uri.path
@stmt[:cookies_for_domain].execute({
:baseDomain => thost.domain || thost.hostname,
:appId => @app_id,
:inBrowserElement => @in_browser_element ? 1 : 0,
:expiry => now.to_i,
}).each { |row|
if secure = row['isSecure'] != 0
next unless URI::HTTPS === uri
end
cookie = HTTP::Cookie.new({}.tap { |attrs|
attrs[:name] = row['name']
attrs[:value] = row['value']
attrs[:domain] = row['host']
attrs[:path] = row['path']
attrs[:expires_at] = Time.at(row['expiry'])
attrs[:accessed_at] = Time.at(row['lastAccessed'] || 0)
attrs[:created_at] = Time.at(row['creationTime'] || 0)
attrs[:secure] = secure
attrs[:httponly] = row['isHttpOnly'] != 0
})
if cookie.valid_for_uri?(uri)
cookie.accessed_at = now
@stmt[:update_lastaccessed].execute({
'lastAccessed' => now.to_i,
'id' => row['id'],
})
yield cookie
end
}
@sjar.each(uri, &block)
else
@stmt[:all_cookies].execute({
:appId => @app_id,
:inBrowserElement => @in_browser_element ? 1 : 0,
:expiry => now.to_i,
}).each { |row|
cookie = HTTP::Cookie.new({}.tap { |attrs|
attrs[:name] = row['name']
attrs[:value] = row['value']
attrs[:domain] = row['host']
attrs[:path] = row['path']
attrs[:expires_at] = Time.at(row['expiry'])
attrs[:accessed_at] = Time.at(row['lastAccessed'] || 0)
attrs[:created_at] = Time.at(row['creationTime'] || 0)
attrs[:secure] = row['isSecure'] != 0
attrs[:httponly] = row['isHttpOnly'] != 0
})
yield cookie
}
@sjar.each(&block)
end
self
end