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

Returns a new instance of Cookie.

[View source] [View on GitHub]

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)

Returns the comment describing the purpose of this cookie, or nil if no such comment has been defined.

Returns:

  • (String)

    Returns the comment describing the purpose of this cookie, or nil if no such comment has been defined.

[View on GitHub]

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)

Returns If a user agent (web browser) presents this cookie to a user, the cookie’s purpose will be described by the information at this URL.

Returns:

  • (String)

    If a user agent (web browser) presents this cookie to a user, the cookie’s purpose will be described by the information at this URL.

[View on GitHub]

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)

Returns domain attribute of the cookie.

Returns:

  • (String)

    Returns domain attribute of the cookie.

[View on GitHub]

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.

[View on GitHub]

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

def expires
  @expires
end

#expiry_dateTime (readonly)

Returns the expiration Date of the cookie, or nil if none exists.

Returns:

  • (Time)

    Returns the expiration Date of the cookie, or nil if none exists.

[View on GitHub]

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)

Returns the name of the cookie.

Returns:

  • (String)

    Returns the name of the cookie.

[View on GitHub]

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)

Returns the path attribute of the cookie.

Returns:

  • (String)

    Returns the path attribute of the cookie.

[View on GitHub]

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)

Returns the ports attribute of the cookie.

Returns:

  • (Array<Integer>)

    Returns the ports attribute of the cookie.

[View on GitHub]

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)

Returns the version of the cookie specification to which this cookie conforms.

Returns:

  • (Integer)

    Returns the version of the cookie specification to which this cookie conforms.

[View on GitHub]

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)

Returns the cookie value

Returns:

  • (Array<Integer>)

    Returns the cookie value

[View on GitHub]

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

[View source] [View on GitHub]

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
[View source] [View on GitHub]

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

Returns Whether this cookie is expired at the comparison date.

Parameters:

  • date (Time) (defaults to: Time.now)

    Time to compare against

Returns:

  • (Boolean)

    Whether this cookie is expired at the comparison date

[View source] [View on GitHub]

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

Returns:

  • (Boolean)
[View source] [View on GitHub]

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

def persistent?
  @persistent
end

#secure?Boolean

Whether this is a HTTPS-only cookie

Returns:

  • (Boolean)
[View source] [View on GitHub]

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

def secure?
  @secure
end

#session?Boolean

Whether this is a session-only cookie

Returns:

  • (Boolean)
[View source] [View on GitHub]

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

def session?
  !@persistent
end