http-cookie 1.0.0.pre9 → 1.0.0.pre10
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 +44 -22
- data/lib/http/cookie.rb +14 -30
- data/lib/http/cookie/version.rb +1 -1
- data/lib/http/cookie_jar.rb +26 -25
- data/lib/http/cookie_jar/cookiestxt_saver.rb +1 -2
- data/test/test_http_cookie.rb +32 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f409469763d06151a3094c2246c64c71f8f0016a
|
4
|
+
data.tar.gz: 4c6433fa901c541aa2bf16461fbbe817fca00f4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec86eccfc64ce5e1672b0ed786722deda4c0386deb564c7eec89ba965199717b603e517a8acdd0cbd560380585e8ed96e66ff9d8cf227ca716ab9c9b4dfabec1
|
7
|
+
data.tar.gz: ad8af975e1ec653bd2e978f21a1c8199160598c16a8bad6851a9d6b6a2ee3e069409858b31a7f076e37c59f697eeeec6f43b9309b6eff51f5acbc0767d9ac4e4
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# HTTP::Cookie
|
2
2
|
|
3
|
-
|
3
|
+
HTTP::Cookie is a ruby library to handle HTTP cookies in a way both
|
4
4
|
compliant with RFCs and compatible with today's major browsers.
|
5
5
|
|
6
6
|
It was originally a part of the
|
@@ -60,14 +60,16 @@ Or install it yourself as:
|
|
60
60
|
set_cookie_header_value = cookies.set_cookie_value(my_url)
|
61
61
|
|
62
62
|
|
63
|
-
## Incompatibilities with
|
63
|
+
## Incompatibilities with Mechanize::Cookie/CookieJar
|
64
64
|
|
65
65
|
There are several incompatibilities between
|
66
|
-
|
67
|
-
is how to rewrite existing code written for
|
68
|
-
equivalent using
|
66
|
+
Mechanize::Cookie/CookieJar and HTTP::Cookie/CookieJar. Below
|
67
|
+
is how to rewrite existing code written for Mechanize::Cookie with
|
68
|
+
equivalent using HTTP::Cookie:
|
69
69
|
|
70
|
-
-
|
70
|
+
- Mechanize::Cookie.parse
|
71
|
+
|
72
|
+
The parameter order changed in HTTP::Cookie.parse.
|
71
73
|
|
72
74
|
# before
|
73
75
|
cookies1 = Mechanize::Cookie.parse(uri, set_cookie1)
|
@@ -77,7 +79,21 @@ equivalent using `HTTP::Cookie`:
|
|
77
79
|
cookies1 = HTTP::Cookie.parse(set_cookie1, uri_or_url)
|
78
80
|
cookies2 = HTTP::Cookie.parse(set_cookie2, uri_or_url, :logger => log)
|
79
81
|
|
80
|
-
-
|
82
|
+
- Mechanize::Cookie#version, #version=
|
83
|
+
|
84
|
+
There is no longer a sense of version in HTTP cookie. The only
|
85
|
+
version number that has ever been defined was zero, and there will
|
86
|
+
be no other version since the version attribute has been removed
|
87
|
+
in RFC 6265.
|
88
|
+
|
89
|
+
- Mechanize::Cookie#comment, #comment=
|
90
|
+
|
91
|
+
Ditto. The comment attribute has been removed in RFC 6265.
|
92
|
+
|
93
|
+
- Mechanize::Cookie#set_domain
|
94
|
+
|
95
|
+
This method was unintentionally made public. Simply use
|
96
|
+
HTTP::Cookie#domain=.
|
81
97
|
|
82
98
|
# before
|
83
99
|
cookie.set_domain(domain)
|
@@ -85,7 +101,9 @@ equivalent using `HTTP::Cookie`:
|
|
85
101
|
# after
|
86
102
|
cookie.domain = domain
|
87
103
|
|
88
|
-
-
|
104
|
+
- Mechanize::CookieJar#add, #add!
|
105
|
+
|
106
|
+
Always use HTTP::CookieJar#add.
|
89
107
|
|
90
108
|
# before
|
91
109
|
jar.add!(cookie1)
|
@@ -95,7 +113,9 @@ equivalent using `HTTP::Cookie`:
|
|
95
113
|
jar.add(cookie1)
|
96
114
|
cookie2.origin = uri; jar.add(cookie2) # or specify origin in parse() or new()
|
97
115
|
|
98
|
-
-
|
116
|
+
- Mechanize::CookieJar#clear!
|
117
|
+
|
118
|
+
Use HTTP::Cookiejar#clear.
|
99
119
|
|
100
120
|
# before
|
101
121
|
jar.clear!
|
@@ -103,7 +123,9 @@ equivalent using `HTTP::Cookie`:
|
|
103
123
|
# after
|
104
124
|
jar.clear
|
105
125
|
|
106
|
-
-
|
126
|
+
- Mechanize::CookieJar#save_as
|
127
|
+
|
128
|
+
Use HTTP::CookieJar#save.
|
107
129
|
|
108
130
|
# before
|
109
131
|
jar.save_as(file)
|
@@ -111,34 +133,34 @@ equivalent using `HTTP::Cookie`:
|
|
111
133
|
# after
|
112
134
|
jar.save(file)
|
113
135
|
|
114
|
-
-
|
136
|
+
- Mechanize::CookieJar#jar
|
115
137
|
|
116
|
-
There is no direct access to the internal hash in
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
138
|
+
There is no direct access to the internal hash in HTTP::CookieJar
|
139
|
+
since it has introduced an abstract store layer. If you want to
|
140
|
+
tweak the internals of the hash store, try creating a new store
|
141
|
+
class referring to the default store class
|
142
|
+
HTTP::CookieJar::HashStore.
|
121
143
|
|
122
144
|
If you desperately need it you can access it by
|
123
145
|
`jar.store.instance_variable_get(:@jar)`, but there is no
|
124
146
|
guarantee that it will remain available in the future.
|
125
147
|
|
126
148
|
|
127
|
-
|
149
|
+
HTTP::Cookie/CookieJar raise runtime errors to help migration, so
|
128
150
|
after replacing the class names, try running your test code once to
|
129
151
|
find out how to fix your code base.
|
130
152
|
|
131
153
|
### File formats
|
132
154
|
|
133
|
-
The YAML serialization format has changed, and
|
155
|
+
The YAML serialization format has changed, and HTTP::CookieJar#load
|
134
156
|
cannot import what is written in a YAML file saved by
|
135
|
-
|
136
|
-
|
157
|
+
Mechanize::CookieJar#save_as. HTTP::CookieJar#load will not raise an
|
158
|
+
exception if an incompatible YAML file is given, but the content is
|
137
159
|
silently ignored.
|
138
160
|
|
139
161
|
Note that there is (obviously) no forward compatibillity with this.
|
140
|
-
Trying to load a YAML file saved by
|
141
|
-
|
162
|
+
Trying to load a YAML file saved by HTTP::CookieJar with
|
163
|
+
Mechanize::CookieJar will fail in runtime error.
|
142
164
|
|
143
165
|
On the other hand, there has been (and will ever be) no change in the
|
144
166
|
cookies.txt format, so use it instead if compatibility is significant.
|
data/lib/http/cookie.rb
CHANGED
@@ -95,8 +95,8 @@ class HTTP::Cookie
|
|
95
95
|
# The cookie domain.
|
96
96
|
#
|
97
97
|
# Setting a domain with a leading dot implies that the #for_domain
|
98
|
-
# flag should be turned on. The setter accepts a
|
99
|
-
#
|
98
|
+
# flag should be turned on. The setter accepts a DomainName object
|
99
|
+
# as well as a string-like.
|
100
100
|
#
|
101
101
|
# :attr_accessor: domain
|
102
102
|
|
@@ -147,8 +147,8 @@ class HTTP::Cookie
|
|
147
147
|
# string, downcased or not.
|
148
148
|
#
|
149
149
|
# This methods accepts any attribute name for which a setter method
|
150
|
-
# is defined. Beware, however, any error (typically
|
151
|
-
#
|
150
|
+
# is defined. Beware, however, any error (typically ArgumentError)
|
151
|
+
# a setter method raises will be passed through.
|
152
152
|
#
|
153
153
|
# e.g.
|
154
154
|
#
|
@@ -158,11 +158,8 @@ class HTTP::Cookie
|
|
158
158
|
# new("name" => "uid", "value" => "a12345", "Domain" => 'www.example.org')
|
159
159
|
#
|
160
160
|
def initialize(*args)
|
161
|
-
@version = 0 # Netscape Cookie
|
162
|
-
|
163
161
|
@origin = @domain = @path =
|
164
|
-
@expires = @max_age =
|
165
|
-
@comment = nil
|
162
|
+
@expires = @max_age = nil
|
166
163
|
@secure = @httponly = false
|
167
164
|
@session = true
|
168
165
|
@created_at = @accessed_at = Time.now
|
@@ -195,7 +192,7 @@ class HTTP::Cookie
|
|
195
192
|
origin = val
|
196
193
|
when 'max_age'
|
197
194
|
# Let max_age take precedence over expires
|
198
|
-
max_age = val
|
195
|
+
max_age = val
|
199
196
|
else
|
200
197
|
setter = :"#{skey}="
|
201
198
|
__send__(setter, val) if respond_to?(setter)
|
@@ -259,23 +256,22 @@ class HTTP::Cookie
|
|
259
256
|
#
|
260
257
|
# ### Compatibility Note for Mechanize::Cookie users
|
261
258
|
#
|
262
|
-
# * Order of parameters changed in
|
263
|
-
# `HTTP::Cookie.parse`. Compare these:
|
259
|
+
# * Order of parameters changed in HTTP::Cookie.parse:
|
264
260
|
#
|
265
261
|
# Mechanize::Cookie.parse(uri, set_cookie[, log])
|
266
262
|
#
|
267
263
|
# HTTP::Cookie.parse(set_cookie, uri[, :logger => # log])
|
268
264
|
#
|
269
|
-
# *
|
265
|
+
# * HTTP::Cookie.parse does not accept nil for `set_cookie`.
|
270
266
|
#
|
271
|
-
# *
|
267
|
+
# * HTTP::Cookie.parse does not yield nil nor include nil in an
|
272
268
|
# returned array. It simply ignores unparsable parts.
|
273
269
|
#
|
274
|
-
# *
|
270
|
+
# * HTTP::Cookie.parse is made to follow RFC 6265 to the extent
|
275
271
|
# not terribly breaking interoperability with broken
|
276
272
|
# implementations. In particular, it is capable of parsing
|
277
|
-
# cookie definitions containing double-quotes just as
|
278
|
-
#
|
273
|
+
# cookie definitions containing double-quotes just as naturally
|
274
|
+
# expected.
|
279
275
|
def parse(set_cookie, origin, options = nil, &block)
|
280
276
|
if options
|
281
277
|
logger = options[:logger]
|
@@ -306,10 +302,6 @@ class HTTP::Cookie
|
|
306
302
|
cookie.expires = avalue unless cookie.max_age
|
307
303
|
when 'max-age'
|
308
304
|
cookie.max_age = avalue
|
309
|
-
when 'comment'
|
310
|
-
cookie.comment = avalue
|
311
|
-
when 'version'
|
312
|
-
cookie.version = avalue
|
313
305
|
when 'secure'
|
314
306
|
cookie.secure = avalue
|
315
307
|
when 'httponly'
|
@@ -494,6 +486,8 @@ class HTTP::Cookie
|
|
494
486
|
else
|
495
487
|
str = check_string_type(sec) or
|
496
488
|
raise TypeError, "#{sec.class} is not an Integer or String"
|
489
|
+
/\A-?\d+\z/.match(str) or
|
490
|
+
raise ArgumentError, "invalid Max-Age: #{sec.inspect}"
|
497
491
|
sec = str.to_i
|
498
492
|
end
|
499
493
|
if @session = sec.nil?
|
@@ -519,13 +513,6 @@ class HTTP::Cookie
|
|
519
513
|
self
|
520
514
|
end
|
521
515
|
|
522
|
-
# The version attribute. The only known version of the cookie
|
523
|
-
# format is 0.
|
524
|
-
attr_accessor :version
|
525
|
-
|
526
|
-
# The comment attribute.
|
527
|
-
attr_accessor :comment
|
528
|
-
|
529
516
|
# The time this cookie was created at. This value is used as a base
|
530
517
|
# date for interpreting the Max-Age attribute value. See #expires.
|
531
518
|
attr_accessor :created_at
|
@@ -608,9 +595,6 @@ class HTTP::Cookie
|
|
608
595
|
elsif @expires
|
609
596
|
string << "; Expires=#{@expires.httpdate}"
|
610
597
|
end
|
611
|
-
if @comment
|
612
|
-
string << "; Comment=#{Scanner.quote(@comment)}"
|
613
|
-
end
|
614
598
|
if @httponly
|
615
599
|
string << "; HttpOnly"
|
616
600
|
end
|
data/lib/http/cookie/version.rb
CHANGED
data/lib/http/cookie_jar.rb
CHANGED
@@ -19,13 +19,13 @@ class HTTP::CookieJar
|
|
19
19
|
# : The store class that backs this jar. (default: `:hash`)
|
20
20
|
# A symbol or an instance of a store class is accepted. Symbols are
|
21
21
|
# mapped to store classes, like `:hash` to
|
22
|
-
#
|
23
|
-
#
|
22
|
+
# HTTP::CookieJar::HashStore and `:mozilla` to
|
23
|
+
# HTTP::CookieJar::MozillaStore.
|
24
24
|
#
|
25
25
|
# Any options given are passed through to the initializer of the
|
26
26
|
# specified store class. For example, the `:mozilla`
|
27
|
-
# (
|
28
|
-
#
|
27
|
+
# (HTTP::CookieJar::MozillaStore) store class requires a `:filename`
|
28
|
+
# option. See individual store classes for details.
|
29
29
|
def initialize(options = nil)
|
30
30
|
opthash = {
|
31
31
|
:store => :hash,
|
@@ -57,8 +57,6 @@ class HTTP::CookieJar
|
|
57
57
|
# To be more specific, HTTP::Cookie.new takes an `:origin` option
|
58
58
|
# and HTTP::Cookie.parse takes one via the second argument.
|
59
59
|
#
|
60
|
-
# `HTTP::Cookie.parse`. Compare these:
|
61
|
-
#
|
62
60
|
# # Mechanize::Cookie
|
63
61
|
# jar.add(origin, cookie)
|
64
62
|
# jar.add!(cookie) # no acceptance check is performed
|
@@ -151,20 +149,22 @@ class HTTP::CookieJar
|
|
151
149
|
# Available option keywords are below:
|
152
150
|
#
|
153
151
|
# * `:format`
|
154
|
-
#
|
155
|
-
# <
|
156
|
-
#
|
157
|
-
#
|
158
|
-
#
|
159
|
-
#
|
152
|
+
#
|
153
|
+
# <dl class="rdoc-list note-list">
|
154
|
+
# <dt>:yaml</dt>
|
155
|
+
# <dd>YAML structure (default)</dd>
|
156
|
+
# <dt>:cookiestxt</dt>
|
157
|
+
# <dd>: Mozilla's cookies.txt format</dd>
|
158
|
+
# </dl>
|
160
159
|
#
|
161
160
|
# * `:session`
|
162
|
-
#
|
163
|
-
# <
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
161
|
+
#
|
162
|
+
# <dl class="rdoc-list note-list">
|
163
|
+
# <dt>true</dt>
|
164
|
+
# <dd>Save session cookies as well.</dd>
|
165
|
+
# <dt>false</dt>
|
166
|
+
# <dd>Do not save session cookies. (default)</dd>
|
167
|
+
# </dl>
|
168
168
|
#
|
169
169
|
# All options given are passed through to the underlying cookie
|
170
170
|
# saver module.
|
@@ -212,17 +212,18 @@ class HTTP::CookieJar
|
|
212
212
|
#
|
213
213
|
# Loads cookies recorded in a file or an IO in the format specified
|
214
214
|
# into the jar and returns self. If a given object responds to
|
215
|
-
#
|
215
|
+
# \#read it is taken as an IO, or taken as a filename otherwise.
|
216
216
|
#
|
217
217
|
# Available option keywords are below:
|
218
218
|
#
|
219
219
|
# * `:format`
|
220
|
-
#
|
221
|
-
# <
|
222
|
-
#
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
220
|
+
#
|
221
|
+
# <dl class="rdoc-list note-list">
|
222
|
+
# <dt>:yaml</dt>
|
223
|
+
# <dd>YAML structure (default)</dd>
|
224
|
+
# <dt>:cookiestxt</dt>
|
225
|
+
# <dd>Mozilla's cookies.txt format</dd>
|
226
|
+
# </dl>
|
226
227
|
#
|
227
228
|
# All options given are passed through to the underlying cookie
|
228
229
|
# saver module.
|
data/test/test_http_cookie.rb
CHANGED
@@ -102,7 +102,6 @@ class TestHTTPCookie < Test::Unit::TestCase
|
|
102
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
|
-
assert_equal 'comment is "comment"', cookie.comment
|
106
105
|
}.size
|
107
106
|
end
|
108
107
|
|
@@ -126,14 +125,19 @@ class TestHTTPCookie < Test::Unit::TestCase
|
|
126
125
|
|
127
126
|
def test_parse_bad_version
|
128
127
|
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
|
-
url = URI.parse('http://
|
130
|
-
|
128
|
+
url = URI.parse('http://192.168.6.196/')
|
129
|
+
# The version attribute is obsolete and simply ignored
|
130
|
+
cookies = HTTP::Cookie.parse(bad_cookie, url)
|
131
|
+
assert_equal 1, cookies.size
|
131
132
|
end
|
132
133
|
|
133
134
|
def test_parse_bad_max_age
|
134
|
-
bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Max-Age=
|
135
|
-
url = URI.parse('http://
|
136
|
-
|
135
|
+
bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Max-Age=forever; Content-type=text/html; Domain=192.168.6.196; expires=Friday, 13-November-2026 23:01:46 GMT;'
|
136
|
+
url = URI.parse('http://192.168.6.196/')
|
137
|
+
# A bad max-age is simply ignored
|
138
|
+
cookies = HTTP::Cookie.parse(bad_cookie, url)
|
139
|
+
assert_equal 1, cookies.size
|
140
|
+
assert_equal nil, cookies.first.max_age
|
137
141
|
end
|
138
142
|
|
139
143
|
def test_parse_date_fail
|
@@ -582,6 +586,28 @@ class TestHTTPCookie < Test::Unit::TestCase
|
|
582
586
|
assert_equal true, cookie.expired?
|
583
587
|
end
|
584
588
|
|
589
|
+
def test_max_age=
|
590
|
+
cookie = HTTP::Cookie.new(cookie_values)
|
591
|
+
|
592
|
+
assert_raises(ArgumentError) {
|
593
|
+
cookie.max_age = "+1"
|
594
|
+
}
|
595
|
+
assert_raises(ArgumentError) {
|
596
|
+
cookie.max_age = "1.5"
|
597
|
+
}
|
598
|
+
assert_raises(ArgumentError) {
|
599
|
+
cookie.max_age = "1 day"
|
600
|
+
}
|
601
|
+
assert_raises(TypeError) {
|
602
|
+
cookie.max_age = [1]
|
603
|
+
}
|
604
|
+
cookie.max_age = "12"
|
605
|
+
assert_equal 12, cookie.max_age
|
606
|
+
|
607
|
+
cookie.max_age = -3
|
608
|
+
assert_equal -3, cookie.max_age
|
609
|
+
end
|
610
|
+
|
585
611
|
def test_session
|
586
612
|
cookie = HTTP::Cookie.new(cookie_values)
|
587
613
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-cookie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.pre10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akinori MUSHA
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-04-
|
14
|
+
date: 2013-04-07 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: domain_name
|