Class: HTTPal::CookieManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rspider/cookie.rb

Instance Method Summary collapse

Constructor Details

#initializeCookieManager

Returns a new instance of CookieManager.



29
30
31
# File 'lib/rspider/cookie.rb', line 29

def initialize
	@cookies=[]
end

Instance Method Details

#get_cookies_for_uri(uri) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rspider/cookie.rb', line 32

def get_cookies_for_uri(uri)
	hs = uri.host.split('.')
	hm = (1..hs.length).inject([]) do |c,n|
		c << hs[(-n)..-1].join('.')
	end
	ps = uri.path.split('/')
	pm = ['/']
	ps.length.times do |n|
		pm << ps[0..n].join('/') 
	end
	pm.delete ''
	
	hostmatch = @cookies.inject([]) do |set, cur|
		set << cur if hm.include? cur.domain
		set
	end
	
	# TODO: PATH-MATCH COOKIES
end


52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rspider/cookie.rb', line 52

def set_cookie_for_uri(uri, setcookie)
	return unless setcookie
	newcookies = CookieMonster.parse_set_cookie(setcookie)
	@cookies.instance_eval do
		newcookies.each do |c|
			c.domain = uri.host unless c.domain
			self[index(c)] = c if include?(c)
			self << c unless include?(c)
		end
	end

end