CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/anemone/cookie_store.rb
Views: 11766
1
require 'delegate'
2
require 'webrick/cookie'
3
4
class WEBrick::Cookie
5
def expired?
6
!!expires && expires < Time.now
7
end
8
end
9
10
module Anemone
11
class CookieStore < DelegateClass(Hash)
12
13
def initialize(cookies = nil)
14
@cookies = {}
15
cookies.each { |name, value| @cookies[name] = WEBrick::Cookie.new(name, value) } if cookies
16
super(@cookies)
17
end
18
19
def merge!(set_cookie_str)
20
begin
21
cookie_hash = WEBrick::Cookie.parse_set_cookies(set_cookie_str).inject({}) do |hash, cookie|
22
hash[cookie.name] = cookie if !!cookie
23
hash
24
end
25
@cookies.merge! cookie_hash
26
rescue
27
end
28
end
29
30
def to_s
31
@cookies.values.reject { |cookie| cookie.expired? }.map { |cookie| "#{cookie.name}=#{cookie.value}" }.join(';')
32
end
33
34
end
35
end
36
37