http-cookie 1.0.0.pre7 → 1.0.0.pre8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36d302ade786727a1d6a34617d6f5fd5a0849ad5
4
- data.tar.gz: 9f0f607f3f78427ec0f1737ce770e58aeb831110
3
+ metadata.gz: 2ab53e3207db1e30dadbe6f623adece56c2dd9a7
4
+ data.tar.gz: cc1b6d68f82a1847275e3d16ab122e86d399186d
5
5
  SHA512:
6
- metadata.gz: 2288ba0ccc9dda414610bb4b87765492c480c1aa886c2b7b716c3d57a4373baa2de020cffb4cb93cfbb00f5dd7283a814c98573a3bbcc752f6f213a0dd8f290c
7
- data.tar.gz: b08eb434043d9601cf743ba30a4c279356da12b4da8c243d37f9f8974ebbfe8d8b55fbeb28d2020e9f346aebcd545f5abedd8b8bb9ecb0eb76dc890576491688
6
+ metadata.gz: 308162bbb92376e5140b863141c55501c454fdf676617f018faa4d1098819a4fe9c9ef4b0b2f63423cee7bb862b8a79edde7d914ce940b095544251f49b9018c
7
+ data.tar.gz: ba8f6855bc6255f2d5729407a299fabba71ae0c1488eefc084cd823a424fbc93c6a34c80ccfb36e1b1830a18fcc1d31b4108f4e89d136dd84a443ca967162498
data/README.md CHANGED
@@ -74,8 +74,8 @@ equivalent using `HTTP::Cookie`:
74
74
  cookies2 = Mechanize::Cookie.parse(uri, set_cookie2, log)
75
75
 
76
76
  # after
77
- cookies1 = HTTP::Cookie.parse(set_cookie1, :origin => uri)
78
- cookies2 = HTTP::Cookie.parse(set_cookie2, :origin => uri, :logger => log)
77
+ cookies1 = HTTP::Cookie.parse(set_cookie1, uri_or_url)
78
+ cookies2 = HTTP::Cookie.parse(set_cookie2, uri_or_url, :logger => log)
79
79
 
80
80
  - `Mechanize::Cookie#set_domain`
81
81
 
@@ -232,18 +232,15 @@ class HTTP::Cookie
232
232
  end
233
233
 
234
234
  # Parses a Set-Cookie header value `set_cookie` into an array of
235
- # Cookie objects. Parts (separated by commas) that are malformed
236
- # or invalid are silently ignored. For example, a cookie that a
237
- # given origin is not allowed to issue is not included in the
238
- # resulted array.
235
+ # Cookie objects taking `origin` as the source URI/URL. Parts
236
+ # (separated by commas) that are malformed or invalid are silently
237
+ # ignored. For example, cookies that a given origin is not
238
+ # allowed to issue are excluded from the resulted array.
239
239
  #
240
240
  # If a block is given, each cookie object is passed to the block.
241
241
  #
242
242
  # Available option keywords are below:
243
243
  #
244
- # :origin
245
- # : The cookie's origin URI/URL
246
- #
247
244
  # :created_at
248
245
  # : The creation time of the cookies parsed.
249
246
  #
@@ -252,12 +249,14 @@ class HTTP::Cookie
252
249
  #
253
250
  # ### Compatibility Note for Mechanize::Cookie users
254
251
  #
255
- # * Order of parameters is a slightly different in
252
+ # * Order of parameters changed in
256
253
  # `HTTP::Cookie.parse`. Compare these:
257
254
  #
258
255
  # Mechanize::Cookie.parse(uri, set_cookie[, log])
259
256
  #
260
- # HTTP::Cookie.parse(set_cookie, :origin => uri[, :logger => # log])
257
+ # HTTP::Cookie.parse(set_cookie, uri[, :logger => # log])
258
+ #
259
+ # * `HTTP::Cookie.parse` does not accept nil for `set_cookie`.
261
260
  #
262
261
  # * `HTTP::Cookie.parse` does not yield nil nor include nil in an
263
262
  # returned array. It simply ignores unparsable parts.
@@ -267,12 +266,12 @@ class HTTP::Cookie
267
266
  # implementations. In particular, it is capable of parsing
268
267
  # cookie definitions containing double-quotes just as
269
268
  # naturally expected.
270
- def parse(set_cookie, options = nil, &block)
269
+ def parse(set_cookie, origin, options = nil, &block)
271
270
  if options
272
271
  logger = options[:logger]
273
- origin = options[:origin] and origin = URI(origin)
274
272
  created_at = options[:created_at]
275
273
  end
274
+ origin = URI(origin)
276
275
 
277
276
  [].tap { |cookies|
278
277
  s = Scanner.new(set_cookie, logger)
@@ -416,6 +415,7 @@ class HTTP::Cookie
416
415
 
417
416
  # See #origin.
418
417
  def origin=(origin)
418
+ return origin if origin == @origin
419
419
  @origin.nil? or
420
420
  raise ArgumentError, "origin cannot be changed once it is set"
421
421
  origin = URI(origin)
@@ -545,7 +545,7 @@ class HTTP::Cookie
545
545
  # Returns a string for use in a Cookie header value,
546
546
  # i.e. "name=value".
547
547
  def cookie_value
548
- "#{@name}=#{@value}"
548
+ "#{@name}=#{Scanner.quote(@value)}"
549
549
  end
550
550
  alias to_s cookie_value
551
551
 
@@ -559,7 +559,7 @@ class HTTP::Cookie
559
559
  origin = origin ? URI(origin) : @origin or
560
560
  raise "origin must be specified to produce a value for Set-Cookie"
561
561
 
562
- string = "#{@name}=#{Scanner.quote(@value)}"
562
+ string = cookie_value
563
563
  if @for_domain
564
564
  string << "; Domain=#{@domain}"
565
565
  end
@@ -23,7 +23,7 @@ class HTTP::Cookie::Scanner < StringScanner
23
23
  class << self
24
24
  def quote(s)
25
25
  return s unless s.match(RE_BAD_CHAR)
26
- '"' << s.gsub(RE_BAD_CHAR, "\\\\\\1") << '"'
26
+ '"' << s.gsub(/([\\"])/, "\\\\\\1") << '"'
27
27
  end
28
28
  end
29
29
 
@@ -1,5 +1,5 @@
1
1
  module HTTP
2
2
  class Cookie
3
- VERSION = "1.0.0.pre7"
3
+ VERSION = "1.0.0.pre8"
4
4
  end
5
5
  end
@@ -117,6 +117,29 @@ class HTTP::CookieJar
117
117
  end
118
118
  include Enumerable
119
119
 
120
+ # Parses a Set-Cookie field value `set_cookie` sent from a URI
121
+ # `origin` and adds the cookies parsed as valid to the jar. Returns
122
+ # an array of cookies that have been added. If a block is given, it
123
+ # is called after each cookie is added.
124
+ #
125
+ # `jar.parse(set_cookie, origin)` is a shorthand for this:
126
+ #
127
+ # HTTP::Cookie.parse(set_cookie, origin) { |cookie|
128
+ # jar.add(cookie)
129
+ # }
130
+ #
131
+ # See HTTP::Cookie.parse for available options.
132
+ def parse(set_cookie, origin, options = nil) # :yield: cookie
133
+ if block_given?
134
+ HTTP::Cookie.parse(set_cookie, origin, options) { |cookie|
135
+ add(cookie)
136
+ yield cookie
137
+ }
138
+ else
139
+ HTTP::Cookie.parse(set_cookie, origin, options, &method(:add))
140
+ end
141
+ end
142
+
120
143
  # call-seq:
121
144
  # jar.save(filename_or_io, **options)
122
145
  # jar.save(filename_or_io, format = :yaml, **options)
@@ -48,7 +48,7 @@ class TestHTTPCookie < Test::Unit::TestCase
48
48
  dates.each do |date|
49
49
  cookie = "PREF=1; expires=#{date}"
50
50
  silently do
51
- assert_equal 1, HTTP::Cookie.parse(cookie, :origin => url) { |c|
51
+ assert_equal 1, HTTP::Cookie.parse(cookie, url) { |c|
52
52
  assert c.expires, "Tried parsing: #{date}"
53
53
  assert_equal(true, c.expires < yesterday)
54
54
  }.size
@@ -61,7 +61,7 @@ class TestHTTPCookie < Test::Unit::TestCase
61
61
 
62
62
  uri = URI.parse 'http://example'
63
63
 
64
- assert_equal 1, HTTP::Cookie.parse(cookie_str, :origin => uri) { |cookie|
64
+ assert_equal 1, HTTP::Cookie.parse(cookie_str, uri) { |cookie|
65
65
  assert_equal 'a', cookie.name
66
66
  assert_equal 'b', cookie.value
67
67
  }.size
@@ -72,7 +72,7 @@ class TestHTTPCookie < Test::Unit::TestCase
72
72
 
73
73
  uri = URI.parse 'http://example'
74
74
 
75
- assert_equal 1, HTTP::Cookie.parse(cookie_str, :origin => uri) { |cookie|
75
+ assert_equal 1, HTTP::Cookie.parse(cookie_str, uri) { |cookie|
76
76
  assert_equal 'foo', cookie.name
77
77
  assert_equal 'bar', cookie.value
78
78
  assert_equal '/', cookie.path
@@ -86,11 +86,11 @@ class TestHTTPCookie < Test::Unit::TestCase
86
86
  cookie_str = "foo=#{'Cookie' * 680}; path=/ab/"
87
87
  assert_equal(HTTP::Cookie::MAX_LENGTH - 1, cookie_str.bytesize)
88
88
 
89
- assert_equal 1, HTTP::Cookie.parse(cookie_str, :origin => uri).size
89
+ assert_equal 1, HTTP::Cookie.parse(cookie_str, uri).size
90
90
 
91
- assert_equal 1, HTTP::Cookie.parse(cookie_str.sub(';', 'x;'), :origin => uri).size
91
+ assert_equal 1, HTTP::Cookie.parse(cookie_str.sub(';', 'x;'), uri).size
92
92
 
93
- assert_equal 0, HTTP::Cookie.parse(cookie_str.sub(';', 'xx;'), :origin => uri).size
93
+ assert_equal 0, HTTP::Cookie.parse(cookie_str.sub(';', 'xx;'), uri).size
94
94
  end
95
95
 
96
96
  def test_parse_quoted
@@ -99,7 +99,7 @@ class TestHTTPCookie < Test::Unit::TestCase
99
99
 
100
100
  uri = URI.parse 'http://example'
101
101
 
102
- assert_equal 1, HTTP::Cookie.parse(cookie_str, :origin => uri) { |cookie|
102
+ assert_equal 1, HTTP::Cookie.parse(cookie_str, uri) { |cookie|
103
103
  assert_equal 'quoted', cookie.name
104
104
  assert_equal 'value', cookie.value
105
105
  assert_equal 'comment is "comment"', cookie.comment
@@ -109,7 +109,7 @@ class TestHTTPCookie < Test::Unit::TestCase
109
109
  def test_parse_weird_cookie
110
110
  cookie = 'n/a, ASPSESSIONIDCSRRQDQR=FBLDGHPBNDJCPCGNCPAENELB; path=/'
111
111
  url = URI.parse('http://www.searchinnovation.com/')
112
- assert_equal 1, HTTP::Cookie.parse(cookie, :origin => url) { |c|
112
+ assert_equal 1, HTTP::Cookie.parse(cookie, url) { |c|
113
113
  assert_equal('ASPSESSIONIDCSRRQDQR', c.name)
114
114
  assert_equal('FBLDGHPBNDJCPCGNCPAENELB', c.value)
115
115
  }.size
@@ -118,7 +118,7 @@ class TestHTTPCookie < Test::Unit::TestCase
118
118
  def test_double_semicolon
119
119
  double_semi = 'WSIDC=WEST;; domain=.williams-sonoma.com; path=/'
120
120
  url = URI.parse('http://williams-sonoma.com/')
121
- assert_equal 1, HTTP::Cookie.parse(double_semi, :origin => url) { |cookie|
121
+ assert_equal 1, HTTP::Cookie.parse(double_semi, url) { |cookie|
122
122
  assert_equal('WSIDC', cookie.name)
123
123
  assert_equal('WEST', cookie.value)
124
124
  }.size
@@ -127,13 +127,13 @@ class TestHTTPCookie < Test::Unit::TestCase
127
127
  def test_parse_bad_version
128
128
  bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Version=1.2; Content-type=text/html; Domain=192.168.6.196; expires=Friday, 13-November-2026 23:01:46 GMT;'
129
129
  url = URI.parse('http://localhost/')
130
- assert_equal 0, HTTP::Cookie.parse(bad_cookie, :origin => url).size
130
+ assert_equal 0, HTTP::Cookie.parse(bad_cookie, url).size
131
131
  end
132
132
 
133
133
  def test_parse_bad_max_age
134
134
  bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Max-Age=1.2; Content-type=text/html; Domain=192.168.6.196; expires=Friday, 13-November-2026 23:01:46 GMT;'
135
135
  url = URI.parse('http://localhost/')
136
- assert_equal 0, HTTP::Cookie.parse(bad_cookie, :origin => url).size
136
+ assert_equal 0, HTTP::Cookie.parse(bad_cookie, url).size
137
137
  end
138
138
 
139
139
  def test_parse_date_fail
@@ -146,7 +146,7 @@ class TestHTTPCookie < Test::Unit::TestCase
146
146
  silently do
147
147
  dates.each do |date|
148
148
  cookie = "PREF=1; expires=#{date}"
149
- assert_equal 1, HTTP::Cookie.parse(cookie, :origin => url) { |c|
149
+ assert_equal 1, HTTP::Cookie.parse(cookie, url) { |c|
150
150
  assert_equal(true, c.expires.nil?)
151
151
  }.size
152
152
  end
@@ -158,7 +158,7 @@ class TestHTTPCookie < Test::Unit::TestCase
158
158
 
159
159
  cookie_str = 'a=b; domain=.example.com'
160
160
 
161
- cookie = HTTP::Cookie.parse(cookie_str, :origin => url).first
161
+ cookie = HTTP::Cookie.parse(cookie_str, url).first
162
162
 
163
163
  assert_equal 'example.com', cookie.domain
164
164
  assert cookie.for_domain?
@@ -170,7 +170,7 @@ class TestHTTPCookie < Test::Unit::TestCase
170
170
 
171
171
  cookie_str = 'a=b; domain=example.com'
172
172
 
173
- cookie = HTTP::Cookie.parse(cookie_str, :origin => url).first
173
+ cookie = HTTP::Cookie.parse(cookie_str, url).first
174
174
 
175
175
  assert_equal 'example.com', cookie.domain
176
176
  assert cookie.for_domain?
@@ -178,9 +178,7 @@ class TestHTTPCookie < Test::Unit::TestCase
178
178
  end
179
179
 
180
180
  def test_parse_public_suffix
181
- cookie_str = 'a=b; domain=com'
182
-
183
- cookie = HTTP::Cookie.parse(cookie_str).first
181
+ cookie = HTTP::Cookie.new('a', 'b', :domain => 'com')
184
182
  assert_equal('com', cookie.domain)
185
183
  assert_equal(false, cookie.for_domain?)
186
184
 
@@ -198,7 +196,7 @@ class TestHTTPCookie < Test::Unit::TestCase
198
196
 
199
197
  cookie_str = 'a=b;'
200
198
 
201
- cookie = HTTP::Cookie.parse(cookie_str, :origin => url).first
199
+ cookie = HTTP::Cookie.parse(cookie_str, url).first
202
200
 
203
201
  assert_equal 'example.com', cookie.domain
204
202
  assert !cookie.for_domain?
@@ -211,23 +209,23 @@ class TestHTTPCookie < Test::Unit::TestCase
211
209
  epoch, date = 4485353164, 'Fri, 19 Feb 2112 19:26:04 GMT'
212
210
  base = Time.at(1363014000)
213
211
 
214
- cookie = HTTP::Cookie.parse("name=Akinori; expires=#{date}", :origin => url).first
212
+ cookie = HTTP::Cookie.parse("name=Akinori; expires=#{date}", url).first
215
213
  assert_equal Time.at(epoch), cookie.expires
216
214
 
217
- cookie = HTTP::Cookie.parse('name=Akinori; max-age=3600', :origin => url).first
215
+ cookie = HTTP::Cookie.parse('name=Akinori; max-age=3600', url).first
218
216
  assert_in_delta Time.now + 3600, cookie.expires, 1
219
- cookie = HTTP::Cookie.parse('name=Akinori; max-age=3600', :origin => url, :created_at => base).first
217
+ cookie = HTTP::Cookie.parse('name=Akinori; max-age=3600', url, :created_at => base).first
220
218
  assert_equal base + 3600, cookie.expires
221
219
 
222
220
  # Max-Age has precedence over Expires
223
- cookie = HTTP::Cookie.parse("name=Akinori; max-age=3600; expires=#{date}", :origin => url).first
221
+ cookie = HTTP::Cookie.parse("name=Akinori; max-age=3600; expires=#{date}", url).first
224
222
  assert_in_delta Time.now + 3600, cookie.expires, 1
225
- cookie = HTTP::Cookie.parse("name=Akinori; max-age=3600; expires=#{date}", :origin => url, :created_at => base).first
223
+ cookie = HTTP::Cookie.parse("name=Akinori; max-age=3600; expires=#{date}", url, :created_at => base).first
226
224
  assert_equal base + 3600, cookie.expires
227
225
 
228
- cookie = HTTP::Cookie.parse("name=Akinori; expires=#{date}; max-age=3600", :origin => url).first
226
+ cookie = HTTP::Cookie.parse("name=Akinori; expires=#{date}; max-age=3600", url).first
229
227
  assert_in_delta Time.now + 3600, cookie.expires, 1
230
- cookie = HTTP::Cookie.parse("name=Akinori; expires=#{date}; max-age=3600", :origin => url, :created_at => base).first
228
+ cookie = HTTP::Cookie.parse("name=Akinori; expires=#{date}; max-age=3600", url, :created_at => base).first
231
229
  assert_equal base + 3600, cookie.expires
232
230
  end
233
231
 
@@ -241,7 +239,7 @@ class TestHTTPCookie < Test::Unit::TestCase
241
239
  'name=Akinori; expires=',
242
240
  'name=Akinori; max-age=',
243
241
  ].each { |str|
244
- cookie = HTTP::Cookie.parse(str, :origin => url).first
242
+ cookie = HTTP::Cookie.parse(str, url).first
245
243
  assert cookie.session?, str
246
244
  }
247
245
 
@@ -249,7 +247,7 @@ class TestHTTPCookie < Test::Unit::TestCase
249
247
  'name=Akinori; expires=Mon, 19 Feb 2012 19:26:04 GMT',
250
248
  'name=Akinori; max-age=3600',
251
249
  ].each { |str|
252
- cookie = HTTP::Cookie.parse(str, :origin => url).first
250
+ cookie = HTTP::Cookie.parse(str, url).first
253
251
  assert !cookie.session?, str
254
252
  }
255
253
  end
@@ -273,7 +271,7 @@ class TestHTTPCookie < Test::Unit::TestCase
273
271
  "no_domain2=no_domain; Expires=Sun, 06 Nov 2011 00:29:53 GMT; no_expires=nope; Domain, " \
274
272
  "no_domain3=no_domain; Expires=Sun, 06 Nov 2011 00:29:53 GMT; no_expires=nope; Domain="
275
273
 
276
- cookies = HTTP::Cookie.parse cookie_str, :origin => url
274
+ cookies = HTTP::Cookie.parse cookie_str, url
277
275
  assert_equal 15, cookies.length
278
276
 
279
277
  name = cookies.find { |c| c.name == 'name' }
@@ -323,7 +321,7 @@ class TestHTTPCookie < Test::Unit::TestCase
323
321
 
324
322
  cookie_params.keys.combine.each do |keys|
325
323
  cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join('; ')
326
- cookie, = HTTP::Cookie.parse(cookie_text, :origin => url)
324
+ cookie, = HTTP::Cookie.parse(cookie_text, url)
327
325
 
328
326
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
329
327
  assert_equal('/', cookie.path)
@@ -340,7 +338,7 @@ class TestHTTPCookie < Test::Unit::TestCase
340
338
 
341
339
  cookie_params.keys.combine.each do |keys|
342
340
  cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join('; ')
343
- cookie, = HTTP::Cookie.parse(cookie_text, :origin => url)
341
+ cookie, = HTTP::Cookie.parse(cookie_text, url)
344
342
 
345
343
  assert_equal('12345%7D=', cookie.to_s)
346
344
  assert_equal('', cookie.value)
@@ -360,7 +358,7 @@ class TestHTTPCookie < Test::Unit::TestCase
360
358
  cookie_params.keys.combine.each do |keys|
361
359
  next if keys.include?('path')
362
360
  cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join('; ')
363
- cookie, = HTTP::Cookie.parse(cookie_text, :origin => url)
361
+ cookie, = HTTP::Cookie.parse(cookie_text, url)
364
362
 
365
363
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
366
364
  assert_equal('/', cookie.path)
@@ -379,7 +377,7 @@ class TestHTTPCookie < Test::Unit::TestCase
379
377
  cookie_params.keys.combine.each do |keys|
380
378
  next unless keys.include?('secure')
381
379
  cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join('; ')
382
- cookie, = HTTP::Cookie.parse(cookie_text, :origin => url)
380
+ cookie, = HTTP::Cookie.parse(cookie_text, url)
383
381
 
384
382
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
385
383
  assert_equal('/', cookie.path)
@@ -390,6 +388,16 @@ class TestHTTPCookie < Test::Unit::TestCase
390
388
  end
391
389
  end
392
390
 
391
+ def test_cookie_value
392
+ [
393
+ ['foo="bar baz"', 'bar baz'],
394
+ ['foo="bar\"; \"baz"', 'bar"; "baz'],
395
+ ].each { |cookie_value, value|
396
+ cookie = HTTP::Cookie.new('foo', value)
397
+ assert_equal(cookie_value, cookie.cookie_value)
398
+ }
399
+ end
400
+
393
401
  def test_set_cookie_value
394
402
  url = URI.parse('http://rubyforge.org/')
395
403
 
@@ -398,8 +406,8 @@ class TestHTTPCookie < Test::Unit::TestCase
398
406
  date = Time.at(Time.now.to_i)
399
407
  cookie_params.keys.combine.each do |keys|
400
408
  cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join('; ')
401
- cookie, = HTTP::Cookie.parse(cookie_text, :origin => url, :created_at => date)
402
- cookie2, = HTTP::Cookie.parse(cookie.set_cookie_value, :origin => url, :created_at => date)
409
+ cookie, = HTTP::Cookie.parse(cookie_text, url, :created_at => date)
410
+ cookie2, = HTTP::Cookie.parse(cookie.set_cookie_value, url, :created_at => date)
403
411
 
404
412
  assert_equal(cookie.name, cookie2.name)
405
413
  assert_equal(cookie.value, cookie2.value)
@@ -427,7 +435,7 @@ class TestHTTPCookie < Test::Unit::TestCase
427
435
 
428
436
  cookie_params.keys.combine.each do |keys|
429
437
  cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join(';')
430
- cookie, = HTTP::Cookie.parse(cookie_text, :origin => url)
438
+ cookie, = HTTP::Cookie.parse(cookie_text, url)
431
439
 
432
440
  assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
433
441
  assert_equal('/', cookie.path)
@@ -615,11 +623,11 @@ class TestHTTPCookie < Test::Unit::TestCase
615
623
  assert_equal '/foo/bar', uri.path
616
624
 
617
625
  cookie_str = 'a=b'
618
- cookie = HTTP::Cookie.parse(cookie_str, :origin => uri).first
626
+ cookie = HTTP::Cookie.parse(cookie_str, uri).first
619
627
  assert '/foo/', cookie.path
620
628
 
621
629
  cookie_str = 'a=b; path=/foo'
622
- cookie = HTTP::Cookie.parse(cookie_str, :origin => uri).first
630
+ cookie = HTTP::Cookie.parse(cookie_str, uri).first
623
631
  assert '/foo', cookie.path
624
632
 
625
633
  uri = URI.parse('http://example.com')
@@ -627,16 +635,16 @@ class TestHTTPCookie < Test::Unit::TestCase
627
635
  assert_equal '', uri.path
628
636
 
629
637
  cookie_str = 'a=b'
630
- cookie = HTTP::Cookie.parse(cookie_str, :origin => uri).first
638
+ cookie = HTTP::Cookie.parse(cookie_str, uri).first
631
639
  assert '/', cookie.path
632
640
 
633
641
  cookie_str = 'a=b; path=/foo'
634
- cookie = HTTP::Cookie.parse(cookie_str, :origin => uri).first
642
+ cookie = HTTP::Cookie.parse(cookie_str, uri).first
635
643
  assert '/foo', cookie.path
636
644
  end
637
645
 
638
646
  def test_domain_nil
639
- cookie = HTTP::Cookie.parse('a=b').first
647
+ cookie = HTTP::Cookie.new('a', 'b')
640
648
  assert_raises(RuntimeError) {
641
649
  cookie.valid_for_uri?('http://example.com/')
642
650
  }
@@ -646,7 +654,7 @@ class TestHTTPCookie < Test::Unit::TestCase
646
654
  url = URI.parse('http://host.dom.example.com:8080/')
647
655
 
648
656
  cookie_str = 'a=b; domain=Example.Com'
649
- cookie = HTTP::Cookie.parse(cookie_str, :origin => url).first
657
+ cookie = HTTP::Cookie.parse(cookie_str, url).first
650
658
  assert 'example.com', cookie.domain
651
659
 
652
660
  cookie.domain = DomainName(url.host)
@@ -666,8 +674,7 @@ class TestHTTPCookie < Test::Unit::TestCase
666
674
  def test_origin=
667
675
  url = URI.parse('http://example.com/path/')
668
676
 
669
- cookie_str = 'a=b'
670
- cookie = HTTP::Cookie.parse(cookie_str).first
677
+ cookie = HTTP::Cookie.new('a', 'b')
671
678
  cookie.origin = url
672
679
  assert_equal '/path/', cookie.path
673
680
  assert_equal 'example.com', cookie.domain
@@ -676,8 +683,7 @@ class TestHTTPCookie < Test::Unit::TestCase
676
683
  cookie.origin = URI.parse('http://www.example.com/')
677
684
  }
678
685
 
679
- cookie_str = 'a=b; domain=.example.com; path=/'
680
- cookie = HTTP::Cookie.parse(cookie_str).first
686
+ cookie = HTTP::Cookie.new('a', 'b', :domain => '.example.com', :path => '/')
681
687
  cookie.origin = url
682
688
  assert_equal '/', cookie.path
683
689
  assert_equal 'example.com', cookie.domain
@@ -686,8 +692,7 @@ class TestHTTPCookie < Test::Unit::TestCase
686
692
  cookie.origin = URI.parse('http://www.example.com/')
687
693
  }
688
694
 
689
- cookie_str = 'a=b; domain=example.com'
690
- cookie = HTTP::Cookie.parse(cookie_str).first
695
+ cookie = HTTP::Cookie.new('a', 'b', :domain => '.example.com')
691
696
  assert_raises(ArgumentError) {
692
697
  cookie.origin = URI.parse('http://example.org/')
693
698
  }
@@ -706,7 +711,7 @@ class TestHTTPCookie < Test::Unit::TestCase
706
711
  def test_valid_for_uri?
707
712
  {
708
713
  HTTP::Cookie.parse('a1=b',
709
- :origin => 'http://example.com/dir/file.html').first => {
714
+ 'http://example.com/dir/file.html').first => {
710
715
  true => [
711
716
  'http://example.com/dir/',
712
717
  'http://example.com/dir/test.html',
@@ -726,7 +731,7 @@ class TestHTTPCookie < Test::Unit::TestCase
726
731
  ]
727
732
  },
728
733
  HTTP::Cookie.parse('a2=b; path=/dir2/',
729
- :origin => 'http://example.com/dir/file.html').first => {
734
+ 'http://example.com/dir/file.html').first => {
730
735
  true => [
731
736
  'http://example.com/dir2/',
732
737
  'http://example.com/dir2/test.html',
@@ -746,7 +751,7 @@ class TestHTTPCookie < Test::Unit::TestCase
746
751
  ]
747
752
  },
748
753
  HTTP::Cookie.parse('a4=b; domain=example.com; path=/dir2/',
749
- :origin => URI('http://example.com/dir/file.html')).first => {
754
+ URI('http://example.com/dir/file.html')).first => {
750
755
  true => [
751
756
  'https://example.com/dir2/test.html',
752
757
  'http://example.com/dir2/test.html',
@@ -762,7 +767,7 @@ class TestHTTPCookie < Test::Unit::TestCase
762
767
  ]
763
768
  },
764
769
  HTTP::Cookie.parse('a4=b; secure',
765
- :origin => URI('https://example.com/dir/file.html')).first => {
770
+ URI('https://example.com/dir/file.html')).first => {
766
771
  true => [
767
772
  'https://example.com/dir/test.html',
768
773
  ],
@@ -774,7 +779,7 @@ class TestHTTPCookie < Test::Unit::TestCase
774
779
  ]
775
780
  },
776
781
  HTTP::Cookie.parse('a5=b',
777
- :origin => URI('https://example.com/')).first => {
782
+ URI('https://example.com/')).first => {
778
783
  true => [
779
784
  'https://example.com',
780
785
  ],
@@ -783,7 +788,7 @@ class TestHTTPCookie < Test::Unit::TestCase
783
788
  ]
784
789
  },
785
790
  HTTP::Cookie.parse('a6=b; path=/dir',
786
- :origin => 'http://example.com/dir/file.html').first => {
791
+ 'http://example.com/dir/file.html').first => {
787
792
  true => [
788
793
  'http://example.com/dir',
789
794
  'http://example.com/dir/',