Class: Manticore::Cookie

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Cookie



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/manticore/cookie.rb', line 65

def initialize(args)
  @comment = args.fetch(:comment, nil)
  @comment_url = args.fetch(:comment_url, nil)
  @domain = args.fetch(:domain, nil)
  @expires = args.fetch(:expires, nil)
  @name = args.fetch(:name, nil)
  @path = args.fetch(:path, nil)
  @ports = args.fetch(:ports, nil)
  @value = args.fetch(:value, nil)
  @secure = args.fetch(:secure, nil)
  @persistent = args.fetch(:persistent, nil)
  @spec_version = args.fetch(:spec_version, nil)
end

Instance Attribute Details

#commentString (readonly)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/manticore/cookie.rb', line 20

class Cookie
  # @private
  # Create a Manticore::Cookie wrapper from a org.apache.http.cookie.Cookie
  def self.from_java(cookie)
    if cookie.get_expiry_date
      expiry = Time.at(cookie.get_expiry_date / 1000)
    end

    new(
      comment: cookie.get_comment,
      comment_url: cookie.getCommentURL,
      domain: cookie.get_domain,
      expires: expiry,
      name: cookie.get_name,
      path: cookie.get_path,
      ports: cookie.get_ports.to_a,
      value: cookie.get_value,
      secure: cookie.is_secure,
      persistent: cookie.is_persistent,
      spec_version: cookie.get_version,
    )
  end

  def self.from_set_cookie(value)
    opts = {name: nil, value: nil}
    value.split(";").each do |part|
      k, v = part.split("=", 2).map(&:strip)

      if opts[:name].nil?
        opts[:name] = k
        opts[:value] = v
      end

      case k.downcase
      when "domain", "path"
        opts[k.to_sym] = v
      when "secure"
        opts[:secure] = true
      end
    end
    Manticore::Cookie.new opts
  end

  attr_reader :comment, :comment_url, :domain, :expires, :name, :path, :ports, :value, :spec_version

  def initialize(args)
    @comment = args.fetch(:comment, nil)
    @comment_url = args.fetch(:comment_url, nil)
    @domain = args.fetch(:domain, nil)
    @expires = args.fetch(:expires, nil)
    @name = args.fetch(:name, nil)
    @path = args.fetch(:path, nil)
    @ports = args.fetch(:ports, nil)
    @value = args.fetch(:value, nil)
    @secure = args.fetch(:secure, nil)
    @persistent = args.fetch(:persistent, nil)
    @spec_version = args.fetch(:spec_version, nil)
  end

  # @param  date [Time] Time to compare against
  #
  # @return [Boolean] Whether this cookie is expired at the comparison date
  def expired?(date = Time.now)
    @expiry_date > date
  end

  # Whether this is a HTTPS-only cookie
  #
  # @return [Boolean]
  def secure?
    @secure
  end

  # Whether this is a persistent (session-only) cookie
  #
  # @return [Boolean]
  def persistent?
    @persistent
  end

  # Whether this is a session-only cookie
  #
  # @return [Boolean]
  def session?
    !@persistent
  end
end

#comment_urlString (readonly)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/manticore/cookie.rb', line 20

class Cookie
  # @private
  # Create a Manticore::Cookie wrapper from a org.apache.http.cookie.Cookie
  def self.from_java(cookie)
    if cookie.get_expiry_date
      expiry = Time.at(cookie.get_expiry_date / 1000)
    end

    new(
      comment: cookie.get_comment,
      comment_url: cookie.getCommentURL,
      domain: cookie.get_domain,
      expires: expiry,
      name: cookie.get_name,
      path: cookie.get_path,
      ports: cookie.get_ports.to_a,
      value: cookie.get_value,
      secure: cookie.is_secure,
      persistent: cookie.is_persistent,
      spec_version: cookie.get_version,
    )
  end

  def self.from_set_cookie(value)
    opts = {name: nil, value: nil}
    value.split(";").each do |part|
      k, v = part.split("=", 2).map(&:strip)

      if opts[:name].nil?
        opts[:name] = k
        opts[:value] = v
      end

      case k.downcase
      when "domain", "path"
        opts[k.to_sym] = v
      when "secure"
        opts[:secure] = true
      end
    end
    Manticore::Cookie.new opts
  end

  attr_reader :comment, :comment_url, :domain, :expires, :name, :path, :ports, :value, :spec_version

  def initialize(args)
    @comment = args.fetch(:comment, nil)
    @comment_url = args.fetch(:comment_url, nil)
    @domain = args.fetch(:domain, nil)
    @expires = args.fetch(:expires, nil)
    @name = args.fetch(:name, nil)
    @path = args.fetch(:path, nil)
    @ports = args.fetch(:ports, nil)
    @value = args.fetch(:value, nil)
    @secure = args.fetch(:secure, nil)
    @persistent = args.fetch(:persistent, nil)
    @spec_version = args.fetch(:spec_version, nil)
  end

  # @param  date [Time] Time to compare against
  #
  # @return [Boolean] Whether this cookie is expired at the comparison date
  def expired?(date = Time.now)
    @expiry_date > date
  end

  # Whether this is a HTTPS-only cookie
  #
  # @return [Boolean]
  def secure?
    @secure
  end

  # Whether this is a persistent (session-only) cookie
  #
  # @return [Boolean]
  def persistent?
    @persistent
  end

  # Whether this is a session-only cookie
  #
  # @return [Boolean]
  def session?
    !@persistent
  end
end

#domainString (readonly)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/manticore/cookie.rb', line 20

class Cookie
  # @private
  # Create a Manticore::Cookie wrapper from a org.apache.http.cookie.Cookie
  def self.from_java(cookie)
    if cookie.get_expiry_date
      expiry = Time.at(cookie.get_expiry_date / 1000)
    end

    new(
      comment: cookie.get_comment,
      comment_url: cookie.getCommentURL,
      domain: cookie.get_domain,
      expires: expiry,
      name: cookie.get_name,
      path: cookie.get_path,
      ports: cookie.get_ports.to_a,
      value: cookie.get_value,
      secure: cookie.is_secure,
      persistent: cookie.is_persistent,
      spec_version: cookie.get_version,
    )
  end

  def self.from_set_cookie(value)
    opts = {name: nil, value: nil}
    value.split(";").each do |part|
      k, v = part.split("=", 2).map(&:strip)

      if opts[:name].nil?
        opts[:name] = k
        opts[:value] = v
      end

      case k.downcase
      when "domain", "path"
        opts[k.to_sym] = v
      when "secure"
        opts[:secure] = true
      end
    end
    Manticore::Cookie.new opts
  end

  attr_reader :comment, :comment_url, :domain, :expires, :name, :path, :ports, :value, :spec_version

  def initialize(args)
    @comment = args.fetch(:comment, nil)
    @comment_url = args.fetch(:comment_url, nil)
    @domain = args.fetch(:domain, nil)
    @expires = args.fetch(:expires, nil)
    @name = args.fetch(:name, nil)
    @path = args.fetch(:path, nil)
    @ports = args.fetch(:ports, nil)
    @value = args.fetch(:value, nil)
    @secure = args.fetch(:secure, nil)
    @persistent = args.fetch(:persistent, nil)
    @spec_version = args.fetch(:spec_version, nil)
  end

  # @param  date [Time] Time to compare against
  #
  # @return [Boolean] Whether this cookie is expired at the comparison date
  def expired?(date = Time.now)
    @expiry_date > date
  end

  # Whether this is a HTTPS-only cookie
  #
  # @return [Boolean]
  def secure?
    @secure
  end

  # Whether this is a persistent (session-only) cookie
  #
  # @return [Boolean]
  def persistent?
    @persistent
  end

  # Whether this is a session-only cookie
  #
  # @return [Boolean]
  def session?
    !@persistent
  end
end

#expiresObject (readonly)

Returns the value of attribute expires.



63
64
65
# File 'lib/manticore/cookie.rb', line 63

def expires
  @expires
end

#expiry_dateTime (readonly)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/manticore/cookie.rb', line 20

class Cookie
  # @private
  # Create a Manticore::Cookie wrapper from a org.apache.http.cookie.Cookie
  def self.from_java(cookie)
    if cookie.get_expiry_date
      expiry = Time.at(cookie.get_expiry_date / 1000)
    end

    new(
      comment: cookie.get_comment,
      comment_url: cookie.getCommentURL,
      domain: cookie.get_domain,
      expires: expiry,
      name: cookie.get_name,
      path: cookie.get_path,
      ports: cookie.get_ports.to_a,
      value: cookie.get_value,
      secure: cookie.is_secure,
      persistent: cookie.is_persistent,
      spec_version: cookie.get_version,
    )
  end

  def self.from_set_cookie(value)
    opts = {name: nil, value: nil}
    value.split(";").each do |part|
      k, v = part.split("=", 2).map(&:strip)

      if opts[:name].nil?
        opts[:name] = k
        opts[:value] = v
      end

      case k.downcase
      when "domain", "path"
        opts[k.to_sym] = v
      when "secure"
        opts[:secure] = true
      end
    end
    Manticore::Cookie.new opts
  end

  attr_reader :comment, :comment_url, :domain, :expires, :name, :path, :ports, :value, :spec_version

  def initialize(args)
    @comment = args.fetch(:comment, nil)
    @comment_url = args.fetch(:comment_url, nil)
    @domain = args.fetch(:domain, nil)
    @expires = args.fetch(:expires, nil)
    @name = args.fetch(:name, nil)
    @path = args.fetch(:path, nil)
    @ports = args.fetch(:ports, nil)
    @value = args.fetch(:value, nil)
    @secure = args.fetch(:secure, nil)
    @persistent = args.fetch(:persistent, nil)
    @spec_version = args.fetch(:spec_version, nil)
  end

  # @param  date [Time] Time to compare against
  #
  # @return [Boolean] Whether this cookie is expired at the comparison date
  def expired?(date = Time.now)
    @expiry_date > date
  end

  # Whether this is a HTTPS-only cookie
  #
  # @return [Boolean]
  def secure?
    @secure
  end

  # Whether this is a persistent (session-only) cookie
  #
  # @return [Boolean]
  def persistent?
    @persistent
  end

  # Whether this is a session-only cookie
  #
  # @return [Boolean]
  def session?
    !@persistent
  end
end

#nameString (readonly)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/manticore/cookie.rb', line 20

class Cookie
  # @private
  # Create a Manticore::Cookie wrapper from a org.apache.http.cookie.Cookie
  def self.from_java(cookie)
    if cookie.get_expiry_date
      expiry = Time.at(cookie.get_expiry_date / 1000)
    end

    new(
      comment: cookie.get_comment,
      comment_url: cookie.getCommentURL,
      domain: cookie.get_domain,
      expires: expiry,
      name: cookie.get_name,
      path: cookie.get_path,
      ports: cookie.get_ports.to_a,
      value: cookie.get_value,
      secure: cookie.is_secure,
      persistent: cookie.is_persistent,
      spec_version: cookie.get_version,
    )
  end

  def self.from_set_cookie(value)
    opts = {name: nil, value: nil}
    value.split(";").each do |part|
      k, v = part.split("=", 2).map(&:strip)

      if opts[:name].nil?
        opts[:name] = k
        opts[:value] = v
      end

      case k.downcase
      when "domain", "path"
        opts[k.to_sym] = v
      when "secure"
        opts[:secure] = true
      end
    end
    Manticore::Cookie.new opts
  end

  attr_reader :comment, :comment_url, :domain, :expires, :name, :path, :ports, :value, :spec_version

  def initialize(args)
    @comment = args.fetch(:comment, nil)
    @comment_url = args.fetch(:comment_url, nil)
    @domain = args.fetch(:domain, nil)
    @expires = args.fetch(:expires, nil)
    @name = args.fetch(:name, nil)
    @path = args.fetch(:path, nil)
    @ports = args.fetch(:ports, nil)
    @value = args.fetch(:value, nil)
    @secure = args.fetch(:secure, nil)
    @persistent = args.fetch(:persistent, nil)
    @spec_version = args.fetch(:spec_version, nil)
  end

  # @param  date [Time] Time to compare against
  #
  # @return [Boolean] Whether this cookie is expired at the comparison date
  def expired?(date = Time.now)
    @expiry_date > date
  end

  # Whether this is a HTTPS-only cookie
  #
  # @return [Boolean]
  def secure?
    @secure
  end

  # Whether this is a persistent (session-only) cookie
  #
  # @return [Boolean]
  def persistent?
    @persistent
  end

  # Whether this is a session-only cookie
  #
  # @return [Boolean]
  def session?
    !@persistent
  end
end

#pathString (readonly)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/manticore/cookie.rb', line 20

class Cookie
  # @private
  # Create a Manticore::Cookie wrapper from a org.apache.http.cookie.Cookie
  def self.from_java(cookie)
    if cookie.get_expiry_date
      expiry = Time.at(cookie.get_expiry_date / 1000)
    end

    new(
      comment: cookie.get_comment,
      comment_url: cookie.getCommentURL,
      domain: cookie.get_domain,
      expires: expiry,
      name: cookie.get_name,
      path: cookie.get_path,
      ports: cookie.get_ports.to_a,
      value: cookie.get_value,
      secure: cookie.is_secure,
      persistent: cookie.is_persistent,
      spec_version: cookie.get_version,
    )
  end

  def self.from_set_cookie(value)
    opts = {name: nil, value: nil}
    value.split(";").each do |part|
      k, v = part.split("=", 2).map(&:strip)

      if opts[:name].nil?
        opts[:name] = k
        opts[:value] = v
      end

      case k.downcase
      when "domain", "path"
        opts[k.to_sym] = v
      when "secure"
        opts[:secure] = true
      end
    end
    Manticore::Cookie.new opts
  end

  attr_reader :comment, :comment_url, :domain, :expires, :name, :path, :ports, :value, :spec_version

  def initialize(args)
    @comment = args.fetch(:comment, nil)
    @comment_url = args.fetch(:comment_url, nil)
    @domain = args.fetch(:domain, nil)
    @expires = args.fetch(:expires, nil)
    @name = args.fetch(:name, nil)
    @path = args.fetch(:path, nil)
    @ports = args.fetch(:ports, nil)
    @value = args.fetch(:value, nil)
    @secure = args.fetch(:secure, nil)
    @persistent = args.fetch(:persistent, nil)
    @spec_version = args.fetch(:spec_version, nil)
  end

  # @param  date [Time] Time to compare against
  #
  # @return [Boolean] Whether this cookie is expired at the comparison date
  def expired?(date = Time.now)
    @expiry_date > date
  end

  # Whether this is a HTTPS-only cookie
  #
  # @return [Boolean]
  def secure?
    @secure
  end

  # Whether this is a persistent (session-only) cookie
  #
  # @return [Boolean]
  def persistent?
    @persistent
  end

  # Whether this is a session-only cookie
  #
  # @return [Boolean]
  def session?
    !@persistent
  end
end

#portsArray<Integer> (readonly)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/manticore/cookie.rb', line 20

class Cookie
  # @private
  # Create a Manticore::Cookie wrapper from a org.apache.http.cookie.Cookie
  def self.from_java(cookie)
    if cookie.get_expiry_date
      expiry = Time.at(cookie.get_expiry_date / 1000)
    end

    new(
      comment: cookie.get_comment,
      comment_url: cookie.getCommentURL,
      domain: cookie.get_domain,
      expires: expiry,
      name: cookie.get_name,
      path: cookie.get_path,
      ports: cookie.get_ports.to_a,
      value: cookie.get_value,
      secure: cookie.is_secure,
      persistent: cookie.is_persistent,
      spec_version: cookie.get_version,
    )
  end

  def self.from_set_cookie(value)
    opts = {name: nil, value: nil}
    value.split(";").each do |part|
      k, v = part.split("=", 2).map(&:strip)

      if opts[:name].nil?
        opts[:name] = k
        opts[:value] = v
      end

      case k.downcase
      when "domain", "path"
        opts[k.to_sym] = v
      when "secure"
        opts[:secure] = true
      end
    end
    Manticore::Cookie.new opts
  end

  attr_reader :comment, :comment_url, :domain, :expires, :name, :path, :ports, :value, :spec_version

  def initialize(args)
    @comment = args.fetch(:comment, nil)
    @comment_url = args.fetch(:comment_url, nil)
    @domain = args.fetch(:domain, nil)
    @expires = args.fetch(:expires, nil)
    @name = args.fetch(:name, nil)
    @path = args.fetch(:path, nil)
    @ports = args.fetch(:ports, nil)
    @value = args.fetch(:value, nil)
    @secure = args.fetch(:secure, nil)
    @persistent = args.fetch(:persistent, nil)
    @spec_version = args.fetch(:spec_version, nil)
  end

  # @param  date [Time] Time to compare against
  #
  # @return [Boolean] Whether this cookie is expired at the comparison date
  def expired?(date = Time.now)
    @expiry_date > date
  end

  # Whether this is a HTTPS-only cookie
  #
  # @return [Boolean]
  def secure?
    @secure
  end

  # Whether this is a persistent (session-only) cookie
  #
  # @return [Boolean]
  def persistent?
    @persistent
  end

  # Whether this is a session-only cookie
  #
  # @return [Boolean]
  def session?
    !@persistent
  end
end

#spec_versionInteger (readonly)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/manticore/cookie.rb', line 20

class Cookie
  # @private
  # Create a Manticore::Cookie wrapper from a org.apache.http.cookie.Cookie
  def self.from_java(cookie)
    if cookie.get_expiry_date
      expiry = Time.at(cookie.get_expiry_date / 1000)
    end

    new(
      comment: cookie.get_comment,
      comment_url: cookie.getCommentURL,
      domain: cookie.get_domain,
      expires: expiry,
      name: cookie.get_name,
      path: cookie.get_path,
      ports: cookie.get_ports.to_a,
      value: cookie.get_value,
      secure: cookie.is_secure,
      persistent: cookie.is_persistent,
      spec_version: cookie.get_version,
    )
  end

  def self.from_set_cookie(value)
    opts = {name: nil, value: nil}
    value.split(";").each do |part|
      k, v = part.split("=", 2).map(&:strip)

      if opts[:name].nil?
        opts[:name] = k
        opts[:value] = v
      end

      case k.downcase
      when "domain", "path"
        opts[k.to_sym] = v
      when "secure"
        opts[:secure] = true
      end
    end
    Manticore::Cookie.new opts
  end

  attr_reader :comment, :comment_url, :domain, :expires, :name, :path, :ports, :value, :spec_version

  def initialize(args)
    @comment = args.fetch(:comment, nil)
    @comment_url = args.fetch(:comment_url, nil)
    @domain = args.fetch(:domain, nil)
    @expires = args.fetch(:expires, nil)
    @name = args.fetch(:name, nil)
    @path = args.fetch(:path, nil)
    @ports = args.fetch(:ports, nil)
    @value = args.fetch(:value, nil)
    @secure = args.fetch(:secure, nil)
    @persistent = args.fetch(:persistent, nil)
    @spec_version = args.fetch(:spec_version, nil)
  end

  # @param  date [Time] Time to compare against
  #
  # @return [Boolean] Whether this cookie is expired at the comparison date
  def expired?(date = Time.now)
    @expiry_date > date
  end

  # Whether this is a HTTPS-only cookie
  #
  # @return [Boolean]
  def secure?
    @secure
  end

  # Whether this is a persistent (session-only) cookie
  #
  # @return [Boolean]
  def persistent?
    @persistent
  end

  # Whether this is a session-only cookie
  #
  # @return [Boolean]
  def session?
    !@persistent
  end
end

#valueArray<Integer> (readonly)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/manticore/cookie.rb', line 20

class Cookie
  # @private
  # Create a Manticore::Cookie wrapper from a org.apache.http.cookie.Cookie
  def self.from_java(cookie)
    if cookie.get_expiry_date
      expiry = Time.at(cookie.get_expiry_date / 1000)
    end

    new(
      comment: cookie.get_comment,
      comment_url: cookie.getCommentURL,
      domain: cookie.get_domain,
      expires: expiry,
      name: cookie.get_name,
      path: cookie.get_path,
      ports: cookie.get_ports.to_a,
      value: cookie.get_value,
      secure: cookie.is_secure,
      persistent: cookie.is_persistent,
      spec_version: cookie.get_version,
    )
  end

  def self.from_set_cookie(value)
    opts = {name: nil, value: nil}
    value.split(";").each do |part|
      k, v = part.split("=", 2).map(&:strip)

      if opts[:name].nil?
        opts[:name] = k
        opts[:value] = v
      end

      case k.downcase
      when "domain", "path"
        opts[k.to_sym] = v
      when "secure"
        opts[:secure] = true
      end
    end
    Manticore::Cookie.new opts
  end

  attr_reader :comment, :comment_url, :domain, :expires, :name, :path, :ports, :value, :spec_version

  def initialize(args)
    @comment = args.fetch(:comment, nil)
    @comment_url = args.fetch(:comment_url, nil)
    @domain = args.fetch(:domain, nil)
    @expires = args.fetch(:expires, nil)
    @name = args.fetch(:name, nil)
    @path = args.fetch(:path, nil)
    @ports = args.fetch(:ports, nil)
    @value = args.fetch(:value, nil)
    @secure = args.fetch(:secure, nil)
    @persistent = args.fetch(:persistent, nil)
    @spec_version = args.fetch(:spec_version, nil)
  end

  # @param  date [Time] Time to compare against
  #
  # @return [Boolean] Whether this cookie is expired at the comparison date
  def expired?(date = Time.now)
    @expiry_date > date
  end

  # Whether this is a HTTPS-only cookie
  #
  # @return [Boolean]
  def secure?
    @secure
  end

  # Whether this is a persistent (session-only) cookie
  #
  # @return [Boolean]
  def persistent?
    @persistent
  end

  # Whether this is a session-only cookie
  #
  # @return [Boolean]
  def session?
    !@persistent
  end
end

Class Method Details

.from_java(cookie) ⇒ Object

Create a Manticore::Cookie wrapper from a org.apache.http.cookie.Cookie



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/manticore/cookie.rb', line 23

def self.from_java(cookie)
  if cookie.get_expiry_date
    expiry = Time.at(cookie.get_expiry_date / 1000)
  end

  new(
    comment: cookie.get_comment,
    comment_url: cookie.getCommentURL,
    domain: cookie.get_domain,
    expires: expiry,
    name: cookie.get_name,
    path: cookie.get_path,
    ports: cookie.get_ports.to_a,
    value: cookie.get_value,
    secure: cookie.is_secure,
    persistent: cookie.is_persistent,
    spec_version: cookie.get_version,
  )
end


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/manticore/cookie.rb', line 43

def self.from_set_cookie(value)
  opts = {name: nil, value: nil}
  value.split(";").each do |part|
    k, v = part.split("=", 2).map(&:strip)

    if opts[:name].nil?
      opts[:name] = k
      opts[:value] = v
    end

    case k.downcase
    when "domain", "path"
      opts[k.to_sym] = v
    when "secure"
      opts[:secure] = true
    end
  end
  Manticore::Cookie.new opts
end

Instance Method Details

#expired?(date = Time.now) ⇒ Boolean



82
83
84
# File 'lib/manticore/cookie.rb', line 82

def expired?(date = Time.now)
  @expiry_date > date
end

#persistent?Boolean

Whether this is a persistent (session-only) cookie



96
97
98
# File 'lib/manticore/cookie.rb', line 96

def persistent?
  @persistent
end

#secure?Boolean

Whether this is a HTTPS-only cookie



89
90
91
# File 'lib/manticore/cookie.rb', line 89

def secure?
  @secure
end

#session?Boolean

Whether this is a session-only cookie



103
104
105
# File 'lib/manticore/cookie.rb', line 103

def session?
  !@persistent
end