http-cookie 1.0.0.pre3 → 1.0.0.pre4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/http/cookie.rb +26 -24
- data/lib/http/cookie/version.rb +1 -1
- data/lib/http/cookie_jar.rb +49 -29
- data/lib/http/cookie_jar/cookiestxt_saver.rb +1 -1
- data/lib/http/cookie_jar/hash_store.rb +15 -9
- data/lib/http/cookie_jar/mozilla_store.rb +40 -0
- data/test/test_http_cookie.rb +38 -6
- data/test/test_http_cookie_jar.rb +27 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4b4b558d9627051478d3ea9e33579ffedadbe50
|
4
|
+
data.tar.gz: 1c3bfc5bd3379d934cc4aeda4211ad339d4ac9dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5b077b1f4220e1a6c5dc9454f498d2d0757d55584ebad1b19a9f565ab5d91070a519b6c1f75b8118e88efd0542614bc5b15282952bbf12d29bdff9daacacb0c
|
7
|
+
data.tar.gz: f16235e47faae4d97c500ea2ccea5c9a7fc3948c366906ce7ad1a09dd11474754b351a66919e34bbe3e6a9b87ec7f050d7ef3b5f84bb2004f56c2bed613ef4e9
|
data/README.md
CHANGED
@@ -114,10 +114,10 @@ equivalent using `HTTP::Cookie`:
|
|
114
114
|
- `Mechanize::CookieJar#jar`
|
115
115
|
|
116
116
|
There is no direct access to the internal hash in
|
117
|
-
`HTTP::CookieJar` since it has introduced an abstract
|
118
|
-
|
119
|
-
|
120
|
-
|
117
|
+
`HTTP::CookieJar` since it has introduced an abstract store layer.
|
118
|
+
If you want to tweak the internals of the hash store, try creating
|
119
|
+
a new store class referring to the default store class
|
120
|
+
`HTTP::CookieJar::HashStore`.
|
121
121
|
|
122
122
|
If you desperately need it you can access it by
|
123
123
|
`jar.store.instance_variable_get(:@jar)`, but there is no
|
data/lib/http/cookie.rb
CHANGED
@@ -38,7 +38,8 @@ class HTTP::Cookie
|
|
38
38
|
name value
|
39
39
|
domain for_domain path
|
40
40
|
secure httponly
|
41
|
-
expires
|
41
|
+
expires max_age
|
42
|
+
created_at accessed_at
|
42
43
|
]
|
43
44
|
|
44
45
|
if String.respond_to?(:try_convert)
|
@@ -110,8 +111,8 @@ class HTTP::Cookie
|
|
110
111
|
# The setter method accepts a Time object, a string representation
|
111
112
|
# of date/time, or `nil`.
|
112
113
|
#
|
113
|
-
#
|
114
|
-
#
|
114
|
+
# Setting this value resets #max_age to nil. When #max_age is
|
115
|
+
# non-nil, #expires returns `created_at + max_age`.
|
115
116
|
#
|
116
117
|
# :attr_accessor: expires
|
117
118
|
|
@@ -122,8 +123,7 @@ class HTTP::Cookie
|
|
122
123
|
# represents an integer which will be stringified and then
|
123
124
|
# integerized using #to_i.
|
124
125
|
#
|
125
|
-
#
|
126
|
-
# \#max_age resets #expires to nil, and vice versa.
|
126
|
+
# This value is reset to nil when #expires= is called.
|
127
127
|
#
|
128
128
|
# :attr_accessor: max_age
|
129
129
|
|
@@ -232,22 +232,17 @@ class HTTP::Cookie
|
|
232
232
|
# given origin is not allowed to issue is not included in the
|
233
233
|
# resulted array.
|
234
234
|
#
|
235
|
-
# Any Max-Age attribute value found is converted to an expires
|
236
|
-
# value computing from the current time so that expiration check
|
237
|
-
# (#expired?) can be performed.
|
238
|
-
#
|
239
235
|
# If a block is given, each cookie object is passed to the block.
|
240
236
|
#
|
241
237
|
# Available option keywords are below:
|
242
238
|
#
|
243
|
-
#
|
239
|
+
# :origin
|
244
240
|
# : The cookie's origin URI/URL
|
245
241
|
#
|
246
|
-
#
|
247
|
-
# : The
|
248
|
-
# instead of the current time
|
242
|
+
# :created_at
|
243
|
+
# : The creation time of the cookies parsed.
|
249
244
|
#
|
250
|
-
#
|
245
|
+
# :logger
|
251
246
|
# : Logger object useful for debugging
|
252
247
|
#
|
253
248
|
# ### Compatibility Note for Mechanize::Cookie users
|
@@ -271,9 +266,8 @@ class HTTP::Cookie
|
|
271
266
|
if options
|
272
267
|
logger = options[:logger]
|
273
268
|
origin = options[:origin] and origin = URI(origin)
|
274
|
-
|
269
|
+
created_at = options[:created_at]
|
275
270
|
end
|
276
|
-
date ||= Time.now
|
277
271
|
|
278
272
|
[].tap { |cookies|
|
279
273
|
s = Scanner.new(set_cookie, logger)
|
@@ -282,6 +276,7 @@ class HTTP::Cookie
|
|
282
276
|
break if name.nil? || name.empty?
|
283
277
|
|
284
278
|
cookie = new(name, value)
|
279
|
+
cookie.created_at = created_at if created_at
|
285
280
|
attrs.each { |aname, avalue|
|
286
281
|
begin
|
287
282
|
case aname
|
@@ -311,10 +306,6 @@ class HTTP::Cookie
|
|
311
306
|
end
|
312
307
|
}
|
313
308
|
|
314
|
-
# Have `expires` set instead of `max_age`, so that
|
315
|
-
# expiration check (`expired?`) can be performed.
|
316
|
-
cookie.expires = date + cookie.max_age if cookie.max_age
|
317
|
-
|
318
309
|
if origin
|
319
310
|
begin
|
320
311
|
cookie.origin = origin
|
@@ -445,7 +436,9 @@ class HTTP::Cookie
|
|
445
436
|
attr_reader :session
|
446
437
|
alias session? session
|
447
438
|
|
448
|
-
|
439
|
+
def expires
|
440
|
+
@expires or @created_at && @max_age ? @created_at + @max_age : nil
|
441
|
+
end
|
449
442
|
|
450
443
|
# See #expires.
|
451
444
|
def expires=(t)
|
@@ -483,8 +476,11 @@ class HTTP::Cookie
|
|
483
476
|
|
484
477
|
# Tests if this cookie is expired by now, or by a given time.
|
485
478
|
def expired?(time = Time.now)
|
486
|
-
|
487
|
-
|
479
|
+
if expires = self.expires
|
480
|
+
expires <= time
|
481
|
+
else
|
482
|
+
false
|
483
|
+
end
|
488
484
|
end
|
489
485
|
|
490
486
|
# Expires this cookie by setting the expires attribute value to a
|
@@ -501,7 +497,8 @@ class HTTP::Cookie
|
|
501
497
|
# The comment attribute.
|
502
498
|
attr_accessor :comment
|
503
499
|
|
504
|
-
# The time this cookie was created at.
|
500
|
+
# The time this cookie was created at. This value is used as a base
|
501
|
+
# date for interpreting the Max-Age attribute value. See #expires.
|
505
502
|
attr_accessor :created_at
|
506
503
|
|
507
504
|
# The time this cookie was last accessed at.
|
@@ -618,11 +615,16 @@ class HTTP::Cookie
|
|
618
615
|
|
619
616
|
# YAML deserialization helper for Psych.
|
620
617
|
def yaml_initialize(tag, map)
|
618
|
+
expires = nil
|
621
619
|
map.each { |key, value|
|
622
620
|
case key
|
621
|
+
when 'expires'
|
622
|
+
# avoid clobbering max_age
|
623
|
+
expires = value
|
623
624
|
when *PERSISTENT_PROPERTIES
|
624
625
|
__send__(:"#{key}=", value)
|
625
626
|
end
|
626
627
|
}
|
628
|
+
self.expires = expires if self.max_age.nil?
|
627
629
|
end
|
628
630
|
end
|
data/lib/http/cookie/version.rb
CHANGED
data/lib/http/cookie_jar.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# :markup: markdown
|
1
2
|
require 'http/cookie'
|
2
3
|
|
3
4
|
##
|
@@ -10,18 +11,30 @@ class HTTP::CookieJar
|
|
10
11
|
|
11
12
|
attr_reader :store
|
12
13
|
|
13
|
-
# Generates a new cookie jar.
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# store
|
18
|
-
|
19
|
-
|
14
|
+
# Generates a new cookie jar.
|
15
|
+
#
|
16
|
+
# Available option keywords are as below:
|
17
|
+
#
|
18
|
+
# :store
|
19
|
+
# : The store class that backs this jar. (default: `:hash`)
|
20
|
+
# A symbol or an instance of a store class is accepted. Symbols are
|
21
|
+
# mapped to store classes, like `:hash` to
|
22
|
+
# `HTTP::CookieJar::HashStore` and `:mozilla` to
|
23
|
+
# `HTTP::CookieJar::MozillaStore`.
|
24
|
+
#
|
25
|
+
# Any options given are passed through to the initializer of the
|
26
|
+
# specified store class. For example, the `:mozilla`
|
27
|
+
# (`HTTP::CookieJar::MozillaStore`) store class requires a
|
28
|
+
# `:filename` option. See individual store classes for details.
|
29
|
+
def initialize(options = nil)
|
30
|
+
opthash = {
|
31
|
+
:store => :hash,
|
32
|
+
}
|
33
|
+
opthash.update(options) if options
|
34
|
+
case store = opthash[:store]
|
20
35
|
when Symbol
|
21
|
-
@store = AbstractStore.implementation(store).new(
|
36
|
+
@store = AbstractStore.implementation(store).new(opthash)
|
22
37
|
when AbstractStore
|
23
|
-
options.empty? or
|
24
|
-
raise ArgumentError, 'wrong number of arguments (%d for 1)' % (1 + options.size)
|
25
38
|
@store = store
|
26
39
|
else
|
27
40
|
raise TypeError, 'wrong object given as cookie store: %s' % store.inspect
|
@@ -32,7 +45,7 @@ class HTTP::CookieJar
|
|
32
45
|
@store = other.instance_eval { @store.dup }
|
33
46
|
end
|
34
47
|
|
35
|
-
# Adds a
|
48
|
+
# Adds a cookie to the jar and return self. If a given cookie has
|
36
49
|
# no domain or path attribute values and the origin is unknown,
|
37
50
|
# ArgumentError is raised.
|
38
51
|
#
|
@@ -71,7 +84,7 @@ class HTTP::CookieJar
|
|
71
84
|
}.sort
|
72
85
|
end
|
73
86
|
|
74
|
-
# Tests if the jar is empty. If
|
87
|
+
# Tests if the jar is empty. If `url` is given, tests if there is
|
75
88
|
# no cookie for the URL.
|
76
89
|
def empty?(url = nil)
|
77
90
|
if url
|
@@ -84,12 +97,12 @@ class HTTP::CookieJar
|
|
84
97
|
|
85
98
|
# Iterates over all cookies that are not expired.
|
86
99
|
#
|
87
|
-
# An optional argument
|
100
|
+
# An optional argument `uri` specifies a URI/URL indicating the
|
88
101
|
# destination of the cookies being selected. Every cookie yielded
|
89
102
|
# should be good to send to the given URI,
|
90
103
|
# i.e. cookie.valid_for_uri?(uri) evaluates to true.
|
91
104
|
#
|
92
|
-
# If (and only if) the
|
105
|
+
# If (and only if) the `uri` option is given, last access time of
|
93
106
|
# each cookie is updated to the current time.
|
94
107
|
def each(uri = nil, &block)
|
95
108
|
block_given? or return enum_for(__method__, uri)
|
@@ -114,16 +127,21 @@ class HTTP::CookieJar
|
|
114
127
|
#
|
115
128
|
# Available option keywords are below:
|
116
129
|
#
|
117
|
-
# *
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
130
|
+
# * `:format`
|
131
|
+
# <dl class="rdoc-list note-list">
|
132
|
+
# <dt>:yaml</dt>
|
133
|
+
# <dd>YAML structure (default)</dd>
|
134
|
+
# <dt>:cookiestxt</dt>
|
135
|
+
# <dd>: Mozilla's cookies.txt format</dd>
|
136
|
+
# </dl>
|
137
|
+
#
|
138
|
+
# * `:session`
|
139
|
+
# <dl class="rdoc-list note-list">
|
140
|
+
# <dt>true</dt>
|
141
|
+
# <dd>Save session cookies as well.</dd>
|
142
|
+
# <dt>false</dt>
|
143
|
+
# <dd>Do not save session cookies. (default)</dd>
|
144
|
+
# </dl>
|
127
145
|
#
|
128
146
|
# All options given are passed through to the underlying cookie
|
129
147
|
# saver module.
|
@@ -175,11 +193,13 @@ class HTTP::CookieJar
|
|
175
193
|
#
|
176
194
|
# Available option keywords are below:
|
177
195
|
#
|
178
|
-
# *
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
196
|
+
# * `:format`
|
197
|
+
# <dl class="rdoc-list note-list">
|
198
|
+
# <dt>:yaml</dt>
|
199
|
+
# <dd>YAML structure (default)</dd>
|
200
|
+
# <dt>:cookiestxt</dt>
|
201
|
+
# <dd>: Mozilla's cookies.txt format</dd>
|
202
|
+
# </dl>
|
183
203
|
#
|
184
204
|
# All options given are passed through to the underlying cookie
|
185
205
|
# saver module.
|
@@ -9,7 +9,7 @@ end
|
|
9
9
|
# :startdoc:
|
10
10
|
|
11
11
|
class HTTP::CookieJar
|
12
|
-
# A store class that uses a hash
|
12
|
+
# A store class that uses a hash-based cookie store.
|
13
13
|
class HashStore < AbstractStore
|
14
14
|
def default_options
|
15
15
|
{
|
@@ -17,20 +17,26 @@ class HTTP::CookieJar
|
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
20
|
+
# Generates a hash based cookie store.
|
21
|
+
#
|
22
|
+
# Available option keywords are as below:
|
23
|
+
#
|
24
|
+
# :gc_threshold
|
25
|
+
# : GC threshold; A GC happens when this many times cookies have
|
26
|
+
# been stored (default: `HTTP::Cookie::MAX_COOKIES_TOTAL / 20`)
|
20
27
|
def initialize(options = nil)
|
21
28
|
super
|
22
29
|
|
23
|
-
@jar = {
|
24
|
-
# {
|
25
|
-
#
|
26
|
-
#
|
27
|
-
# name => cookie,
|
28
|
-
# ...
|
29
|
-
# },
|
30
|
+
@jar = {
|
31
|
+
# hostname => {
|
32
|
+
# path => {
|
33
|
+
# name => cookie,
|
30
34
|
# ...
|
31
35
|
# },
|
32
36
|
# ...
|
33
|
-
# }
|
37
|
+
# },
|
38
|
+
# ...
|
39
|
+
}
|
34
40
|
|
35
41
|
@gc_index = 0
|
36
42
|
end
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# :markup: markdown
|
1
2
|
require 'http/cookie_jar'
|
2
3
|
require 'sqlite3'
|
3
4
|
|
4
5
|
class HTTP::CookieJar
|
6
|
+
# A store class that uses Mozilla compatible SQLite3 database as
|
7
|
+
# backing store.
|
5
8
|
class MozillaStore < AbstractStore
|
6
9
|
SCHEMA_VERSION = 5
|
7
10
|
|
@@ -26,6 +29,27 @@ class HTTP::CookieJar
|
|
26
29
|
appId inBrowserElement
|
27
30
|
]
|
28
31
|
|
32
|
+
# Generates a Mozilla cookie store. If the file does not exist,
|
33
|
+
# it is created. If it does and its schema is old, it is
|
34
|
+
# automatically upgraded with a new schema keeping the existing
|
35
|
+
# data.
|
36
|
+
#
|
37
|
+
# Available option keywords are as below:
|
38
|
+
#
|
39
|
+
# :filename
|
40
|
+
# : A file name of the SQLite3 database to open. This option is
|
41
|
+
# mandatory.
|
42
|
+
#
|
43
|
+
# :gc_threshold
|
44
|
+
# : GC threshold; A GC happens when this many times cookies have
|
45
|
+
# been stored (default: `HTTP::Cookie::MAX_COOKIES_TOTAL / 20`)
|
46
|
+
#
|
47
|
+
# :app_id
|
48
|
+
# : application ID (default: `0`) to have per application jar.
|
49
|
+
#
|
50
|
+
# :in_browser_element
|
51
|
+
# : a flag to tell if cookies are stored in an in browser
|
52
|
+
# element. (default: `false`)
|
29
53
|
def initialize(options = nil)
|
30
54
|
super
|
31
55
|
|
@@ -39,6 +63,22 @@ class HTTP::CookieJar
|
|
39
63
|
@gc_index = 0
|
40
64
|
end
|
41
65
|
|
66
|
+
# The file name of the SQLite3 database given in initialization.
|
67
|
+
attr_reader :filename
|
68
|
+
|
69
|
+
# Closes the SQLite3 database. After closing, any operation may
|
70
|
+
# raise an error.
|
71
|
+
def close
|
72
|
+
@db.close
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
# Tests if the SQLite3 database is closed.
|
77
|
+
def closed?
|
78
|
+
@db.closed?
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns the schema version of the database.
|
42
82
|
def schema_version
|
43
83
|
@schema_version ||= @db.execute("PRAGMA user_version").first[0]
|
44
84
|
rescue SQLite3::SQLException
|
data/test/test_http_cookie.rb
CHANGED
@@ -200,18 +200,18 @@ class TestHTTPCookie < Test::Unit::TestCase
|
|
200
200
|
|
201
201
|
cookie = HTTP::Cookie.parse('name=Akinori; max-age=3600', :origin => url).first
|
202
202
|
assert_in_delta Time.now + 3600, cookie.expires, 1
|
203
|
-
cookie = HTTP::Cookie.parse('name=Akinori; max-age=3600', :origin => url, :
|
203
|
+
cookie = HTTP::Cookie.parse('name=Akinori; max-age=3600', :origin => url, :created_at => base).first
|
204
204
|
assert_equal base + 3600, cookie.expires
|
205
205
|
|
206
206
|
# Max-Age has precedence over Expires
|
207
207
|
cookie = HTTP::Cookie.parse("name=Akinori; max-age=3600; expires=#{date}", :origin => url).first
|
208
208
|
assert_in_delta Time.now + 3600, cookie.expires, 1
|
209
|
-
cookie = HTTP::Cookie.parse("name=Akinori; max-age=3600; expires=#{date}", :origin => url, :
|
209
|
+
cookie = HTTP::Cookie.parse("name=Akinori; max-age=3600; expires=#{date}", :origin => url, :created_at => base).first
|
210
210
|
assert_equal base + 3600, cookie.expires
|
211
211
|
|
212
212
|
cookie = HTTP::Cookie.parse("name=Akinori; expires=#{date}; max-age=3600", :origin => url).first
|
213
213
|
assert_in_delta Time.now + 3600, cookie.expires, 1
|
214
|
-
cookie = HTTP::Cookie.parse("name=Akinori; expires=#{date}; max-age=3600", :origin => url, :
|
214
|
+
cookie = HTTP::Cookie.parse("name=Akinori; expires=#{date}; max-age=3600", :origin => url, :created_at => base).first
|
215
215
|
assert_equal base + 3600, cookie.expires
|
216
216
|
end
|
217
217
|
|
@@ -382,8 +382,8 @@ class TestHTTPCookie < Test::Unit::TestCase
|
|
382
382
|
date = Time.at(Time.now.to_i)
|
383
383
|
cookie_params.keys.combine.each do |keys|
|
384
384
|
cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join('; ')
|
385
|
-
cookie, = HTTP::Cookie.parse(cookie_text, :origin => url, :
|
386
|
-
cookie2, = HTTP::Cookie.parse(cookie.set_cookie_value, :origin => url, :
|
385
|
+
cookie, = HTTP::Cookie.parse(cookie_text, :origin => url, :created_at => date)
|
386
|
+
cookie2, = HTTP::Cookie.parse(cookie.set_cookie_value, :origin => url, :created_at => date)
|
387
387
|
|
388
388
|
assert_equal(cookie.name, cookie2.name)
|
389
389
|
assert_equal(cookie.value, cookie2.value)
|
@@ -539,7 +539,7 @@ class TestHTTPCookie < Test::Unit::TestCase
|
|
539
539
|
|
540
540
|
cookie.max_age = 3600
|
541
541
|
assert_equal false, cookie.session?
|
542
|
-
assert_equal
|
542
|
+
assert_equal cookie.created_at + 3600, cookie.expires
|
543
543
|
|
544
544
|
cookie.max_age = nil
|
545
545
|
assert_equal true, cookie.session?
|
@@ -775,6 +775,38 @@ class TestHTTPCookie < Test::Unit::TestCase
|
|
775
775
|
}
|
776
776
|
end
|
777
777
|
|
778
|
+
def test_yaml_expires
|
779
|
+
require 'yaml'
|
780
|
+
cookie = HTTP::Cookie.new(cookie_values)
|
781
|
+
|
782
|
+
assert_equal false, cookie.session?
|
783
|
+
assert_equal nil, cookie.max_age
|
784
|
+
|
785
|
+
ycookie = YAML.load(cookie.to_yaml)
|
786
|
+
assert_equal false, ycookie.session?
|
787
|
+
assert_equal nil, ycookie.max_age
|
788
|
+
|
789
|
+
cookie.expires = nil
|
790
|
+
ycookie = YAML.load(cookie.to_yaml)
|
791
|
+
assert_equal true, ycookie.session?
|
792
|
+
assert_equal nil, ycookie.max_age
|
793
|
+
|
794
|
+
cookie.expires = Time.now + 3600
|
795
|
+
ycookie = YAML.load(cookie.to_yaml)
|
796
|
+
assert_equal false, ycookie.session?
|
797
|
+
assert_equal nil, ycookie.max_age
|
798
|
+
|
799
|
+
cookie.max_age = 3600
|
800
|
+
ycookie = YAML.load(cookie.to_yaml)
|
801
|
+
assert_equal false, ycookie.session?
|
802
|
+
assert_equal cookie.created_at + 3600, ycookie.expires
|
803
|
+
|
804
|
+
cookie.max_age = nil
|
805
|
+
ycookie = YAML.load(cookie.to_yaml)
|
806
|
+
assert_equal true, ycookie.session?
|
807
|
+
assert_equal nil, ycookie.expires
|
808
|
+
end
|
809
|
+
|
778
810
|
def test_s_path_match?
|
779
811
|
assert_equal true, HTTP::Cookie.path_match?('/admin/', '/admin/index')
|
780
812
|
assert_equal false, HTTP::Cookie.path_match?('/admin/', '/Admin/index')
|
@@ -363,13 +363,16 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
|
363
363
|
h_cookie = HTTP::Cookie.new(cookie_values(:name => 'Quux',
|
364
364
|
:value => 'Foo#Quux',
|
365
365
|
:httponly => true))
|
366
|
-
|
366
|
+
ma_cookie = HTTP::Cookie.new(cookie_values(:name => 'Maxage',
|
367
|
+
:value => 'Foo#Maxage',
|
368
|
+
:max_age => 15000))
|
367
369
|
@jar.add(cookie)
|
368
370
|
@jar.add(s_cookie)
|
369
371
|
@jar.add(cookie2)
|
370
372
|
@jar.add(h_cookie)
|
373
|
+
@jar.add(ma_cookie)
|
371
374
|
|
372
|
-
assert_equal(
|
375
|
+
assert_equal(5, @jar.cookies(url).length)
|
373
376
|
|
374
377
|
Dir.mktmpdir do |dir|
|
375
378
|
filename = File.join(dir, "cookies.txt")
|
@@ -384,7 +387,7 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
|
384
387
|
jar = HTTP::CookieJar.new
|
385
388
|
jar.load(filename, :cookiestxt) # HACK test the format
|
386
389
|
cookies = jar.cookies(url)
|
387
|
-
assert_equal(
|
390
|
+
assert_equal(4, cookies.length)
|
388
391
|
cookies.each { |cookie|
|
389
392
|
case cookie.name
|
390
393
|
when 'Foo'
|
@@ -407,13 +410,17 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
|
407
410
|
assert_equal true, cookie.for_domain
|
408
411
|
assert_equal '/', cookie.path
|
409
412
|
assert_equal true, cookie.httponly?
|
413
|
+
when 'Maxage'
|
414
|
+
assert_equal 'Foo#Maxage', cookie.value
|
415
|
+
assert_equal nil, cookie.max_age
|
416
|
+
assert_in_delta ma_cookie.expires, cookie.expires, 1
|
410
417
|
else
|
411
418
|
raise
|
412
419
|
end
|
413
420
|
}
|
414
421
|
end
|
415
422
|
|
416
|
-
assert_equal(
|
423
|
+
assert_equal(5, @jar.cookies(url).length)
|
417
424
|
end
|
418
425
|
|
419
426
|
def test_expire_cookies
|
@@ -591,19 +598,27 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
|
591
598
|
def test_max_cookies_hashstore
|
592
599
|
gc_threshold = 150
|
593
600
|
h_test_max_cookies(
|
594
|
-
HTTP::CookieJar.new(
|
601
|
+
HTTP::CookieJar.new(
|
602
|
+
:store => :hash,
|
595
603
|
:gc_threshold => gc_threshold),
|
596
604
|
HTTP::Cookie::MAX_COOKIES_TOTAL + gc_threshold)
|
597
605
|
end
|
598
606
|
|
599
607
|
def test_max_cookies_mozillastore
|
600
608
|
gc_threshold = 150
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
609
|
+
h_test_max_cookies(
|
610
|
+
HTTP::CookieJar.new(
|
611
|
+
:store => :mozilla,
|
612
|
+
:gc_threshold => gc_threshold,
|
613
|
+
:filename => ":memory:"),
|
614
|
+
HTTP::Cookie::MAX_COOKIES_TOTAL + gc_threshold)
|
615
|
+
#Dir.mktmpdir { |dir|
|
616
|
+
# h_test_max_cookies(
|
617
|
+
# HTTP::CookieJar.new(
|
618
|
+
# :store => :mozilla,
|
619
|
+
# :gc_threshold => gc_threshold,
|
620
|
+
# :filename => File.join(dir, "cookies.sqlite")),
|
621
|
+
# HTTP::Cookie::MAX_COOKIES_TOTAL + gc_threshold)
|
622
|
+
#}
|
608
623
|
end
|
609
624
|
end
|