Commit graph

82 commits

Author SHA1 Message Date
Akinori MUSHA
e1857d76a4 Add Cookie.cookie_value and Cookie.cookie_value_to_hash. 2013-04-12 02:15:13 +09:00
Akinori MUSHA
82e65b4a9b Allow assigning nil to the cookie value to make an expiration cookie.
Cookie.new(): Make the value parameter can be omittable.
2013-04-12 02:13:08 +09:00
Akinori MUSHA
917adc1abb Add a test for Cookie#accessed_at. 2013-04-12 01:25:04 +09:00
Akinori MUSHA
f3b8abdd8e Add CookieJar#delete(). 2013-04-12 01:19:39 +09:00
Akinori MUSHA
6689b3b7aa Drop support for obsolete attributes: version and comment. 2013-04-07 23:09:30 +09:00
Akinori MUSHA
9e46ce0d30 Cookie#max_age= should reject malformed strings. 2013-04-07 23:07:20 +09:00
Akinori MUSHA
f5f82c0304 Fix test_parse_bad_version and test_parse_bad_max_age. 2013-04-07 23:02:14 +09:00
Akinori MUSHA
7dba33bd40 Cookie#domain=: Fix handling of an empty string and let it accept nil. 2013-04-03 17:58:41 +09:00
Akinori MUSHA
ffabb614ad Perform acceptance check in CookieJar#add instead of origin=.
- Cookie#acceptable? is added, which is called by such methods as
  Cookie.parse and CookieJar#add.

- Cookie#origin= no longer raises ArgumentError just because it
  conflicts with the domain.

- Cookie#origin= raises ArgumentError if it is given an object that is
  not URI or string-like.
2013-04-03 17:57:27 +09:00
Akinori MUSHA
dc65a98907 HTTP::Cookie.parse: Change the signature again.
I made the uri parameter optional when I introduced the origin
attribute, but on second thought it should always be given.

I'm making the origin parameter fixed and mandatory again, but this
time it comes next to set_cookie.  This order should look more natural
because the one that comes first is to be parsed.

Since Mechanize::Cookie.parse required the uri parameter to be a URI
object, backward compatibility is still possible.
2013-03-29 01:39:30 +09:00
Akinori MUSHA
ef7bdeefba Cookie#cookie_value too should quote values if necessary. 2013-03-28 22:06:19 +09:00
Akinori MUSHA
2dc17ab7dc Better indentation while test is passing. 2013-03-28 19:24:05 +09:00
Akinori MUSHA
8d7da32cc3 Fully test MozillaStore as well as HashStore. 2013-03-27 02:49:55 +09:00
Akinori MUSHA
11a9df8559 Fix handling of the :for_domain option in HTTP::Cookie.new(). 2013-03-28 01:46:42 +09:00
Akinori MUSHA
c5252649c8 Add some tests that fail to spot bugs. 2013-03-28 00:34:49 +09:00
Akinori MUSHA
d76101722d Catch IndexError instead. 2013-03-27 20:40:56 +09:00
Akinori MUSHA
4ebce92fad Rescue LoadError. 2013-03-27 20:16:05 +09:00
Akinori MUSHA
619b915a94 Fix test_yaml_expires taking care of time precisions. 2013-03-27 20:08:27 +09:00
Akinori MUSHA
683141da59 Use :memory: database to save test time. 2013-03-27 19:50:31 +09:00
Akinori MUSHA
eed7e57813 Use the cookie creation time as base time for Max-Age.
Now #expire returns created_at + max_age when expires is nil.

Cookie.parse: the :date keyword is renamed to :created_at, and the
value is set to in parsed cookies via #created_at.

In YAML serialization, #max_age is stored.
2013-03-27 19:50:30 +09:00
Akinori MUSHA
a0ea64da56 CookieJar.new: Pass the store class via a :store keyword. 2013-03-27 17:43:58 +09:00
Akinori MUSHA
6fade20c59 Make GC threshold user specifiable. 2013-03-27 16:10:05 +09:00
Akinori MUSHA
69b3186666 Add MozillaStore. 2013-03-27 16:01:48 +09:00
Akinori MUSHA
bd3ae6c1ae CookiestxtSaver: Hide HttpOnly cookies from old browsers.
This trick is the one that has been used in Mozilla before switching
the cookie database to SQLite.
2013-03-26 15:37:50 +09:00
Akinori MUSHA
8b78e3d1e4 CookiestxtSaver: Prefix the domain field with a dot if the domain flag is on.
The leading dot itself should be meaningless since there is the second
field to tell if the cookie is issued for a domain and that was the
reason I once removed it, but on second thought it doesn't hurt to put
one.
2013-03-26 15:37:50 +09:00
Akinori MUSHA
f2ea366de2 Add HTTP::Cookie#dot_domain. 2013-03-26 01:48:27 +09:00
Akinori MUSHA
5b78957e19 Conform to RFC 6265 5.1.4 in that path=/a matches /a/* but not /ab.
Remove HTTP::Cookie.normalize_path and add HTTP::Cookie.path_match?
instead for comparison.
2013-03-23 02:02:56 +09:00
Akinori MUSHA
4cbea79c00 Improve tests for valid_for_uri?. 2013-03-23 01:54:58 +09:00
Akinori MUSHA
d47e2fe8ad Add tests for #path. 2013-03-23 01:39:46 +09:00
Akinori MUSHA
38f7e98f09 Replace compatibility errors with documentation.
Leave compatibility stuff to Mechanize itself and just keep
http-cookie clean.
2013-03-23 00:27:38 +09:00
Akinori MUSHA
ddf74fee1e Rewrite the Set-Cookie header parser entirely.
The new parser is almost RFC 6265 compliant as the previous
implementation but has some extensions:

- It can parse double-quoted values with unsafe characters inside
  escaped with the backslash.

- It parses a date value of the expires attribute in the way the RFC
  describes, with an exception that it allows omission of the seconds
  field.  Some of the broken date representations that used to pass
  are now treated as error and ignored.

- It can parse a Set-Cookie value that contains multiple cookie
  definitions separated by comma, and commas put inside double quotes
  are not mistaken as definition separator.
2013-03-21 15:52:22 +09:00
Akinori MUSHA
66f37b20dd Rename expire to expire!, to reduce the risk of making a typo. 2013-03-21 15:46:45 +09:00
Akinori MUSHA
5d0bc5f67d Disallow some more bad characters in name=/value=. 2013-03-21 15:46:45 +09:00
Akinori MUSHA
cc6780a5bc A relative path must be treated as the root path as per RFC 6265 5.1.4. 2013-03-21 15:46:45 +09:00
Akinori MUSHA
f14c1786cd Make expires and max_age affect each other and drop session=(). 2013-03-21 15:46:45 +09:00
Akinori MUSHA
ceea67add9 Drop multi-byte characters from the test, which are not allowed. 2013-03-21 15:46:45 +09:00
Akinori MUSHA
7d81c10914 A cookie value may be DQUOTE'd as per RFC 6265 2.2.
Escaping with the backslash character is not mentioned in the RFC but
the backslash character is not allowed here anyway, so just be nice
and support it for legacy applications.
2013-03-21 15:46:45 +09:00
Akinori MUSHA
dff0f57614 Delete trailing whitespace. 2013-03-18 00:43:52 +09:00
Akinori MUSHA
9768154e82 Dir.tmpdir should be mktmpdir here. 2013-03-18 00:39:55 +09:00
Akinori MUSHA
c389a52e2c Drop dependency on WEBrick::HTTPUtils. 2013-03-18 00:09:01 +09:00
Akinori MUSHA
6d3f4ee2dd parse() ignores bad cookies. 2013-03-18 00:06:20 +09:00
Akinori MUSHA
4a5eb9801a Test that parse() actually returns a cookie. 2013-03-18 00:05:31 +09:00
Akinori MUSHA
f936d91521 1.8 compatibility: Fix syntax and remove dependency on hash key order. 2013-03-15 12:13:59 +09:00
Akinori MUSHA
b2920eda0f Do not chdir in test. It breaks autoloads since test is run with -Ilib. 2013-03-15 12:12:53 +09:00
Akinori MUSHA
8be03978a0 Make each(uri) not fail if a non-HTTP URL is given.
Fix documents with #each.  The uri argument was not made a keyword
argument.

Guarantee that the +uri+ given to AbstractStore#each() is a URI
object.

Make HashStore#each return self as required.
2013-03-15 11:33:54 +09:00
Akinori MUSHA
b86690cb21 Check if the scheme is http(s) and the host is non-nil in URI. 2013-03-15 11:21:57 +09:00
Akinori MUSHA
c0d5f3a121 Add error messages to make migration from Mechanize::Cookie easier.
Add a section to elaborate on the incompatibilities to README.md.
2013-03-15 05:53:11 +09:00
Akinori MUSHA
8d8f01fa81 Cap the numbers of cookies per domain and cookies total, respectively.
This is implemented in HashStore#cleanup(), which is automatically
called by #add() after every 150 updates.
2013-03-15 04:20:59 +09:00
Akinori MUSHA
1f5eb6bc7f Introduce an abstraction layer for saving (serializing) CookieJar.
CookieJar#save is the new name for the now obsolete #save_as.

CookieJar#save and #load now accept IO-like instead of a filename.

Change the YAML file format, and make #load discard incompatible data.
2013-03-15 04:20:59 +09:00
Akinori MUSHA
fd7450717a Implement HTTP::CookieJar#empty? without an argument. 2013-03-15 04:20:59 +09:00