| Class | HTTP::Cookie |
| In: |
lib/http/cookie/version.rb
lib/http/cookie.rb |
| Parent: | Object |
| VERSION | = | "1.0.3" | ||
| MAX_LENGTH | = | 4096 | Maximum number of bytes per cookie (RFC 6265 6.1 requires 4096 at least) | |
| MAX_COOKIES_PER_DOMAIN | = | 50 | Maximum number of cookies per domain (RFC 6265 6.1 requires 50 at least) | |
| MAX_COOKIES_TOTAL | = | 3000 | Maximum number of cookies total (RFC 6265 6.1 requires 3000 at least) |
| for_domain | -> | for_domain? |
| secure | -> | secure? |
| httponly | -> | httponly? |
| session | -> | session? |
| accessed_at | [RW] | The time this cookie was last accessed at. |
| created_at | [RW] | The time this cookie was created at. This value is used as a base date for interpreting the Max-Age attribute value. See expires. |
| domain | [R] | |
| domain_name | [R] | Returns the domain attribute value as a DomainName object. |
| for_domain | [RW] |
The domain flag. (the opposite of host-only-flag)
If this flag is true, this cookie will be sent to any host in the \domain, including the host domain itself. If it is false, this cookie will be sent only to the host indicated by the domain. |
| httponly | [RW] |
The HttpOnly flag. (http-only-flag)
A cookie with this flag on should be hidden from a client script. |
| max_age | [R] | |
| name | [R] | |
| origin | [R] | |
| path | [R] | |
| secure | [RW] |
The secure flag. (secure-only-flag)
A cookie with this flag on should only be sent via a secure protocol like HTTPS. |
| session | [R] |
The session flag. (the opposite of persistent-flag)
A cookie with this flag on should be hidden from a client script. |
| value | [R] |
Takes an array of cookies and returns a string for use in the Cookie header, like "name1=value2; name2=value2".
Parses a Cookie header value into a hash of name-value string pairs. The first appearance takes precedence if multiple pairs with the same name occur.
Creates a cookie object. For each key of `attr_hash`, the setter is called if defined and any error (typically ArgumentError or TypeError) that is raised will be passed through. Each key can be either a downcased symbol or a string that may be mixed case. Support for the latter may, however, be obsoleted in future when Ruby 2.0‘s keyword syntax is adopted.
If `value` is omitted or it is nil, an expiration cookie is created unless `max_age` or `expires` (`expires_at`) is given.
e.g.
new("uid", "a12345")
new("uid", "a12345", :domain => 'example.org',
:for_domain => true, :expired => Time.now + 7*86400)
new("name" => "uid", "value" => "a12345", "Domain" => 'www.example.org')
Parses a Set-Cookie header value `set_cookie` assuming that it is sent from a source URI/URL `origin`, and returns an array of Cookie objects. Parts (separated by commas) that are malformed or considered unacceptable are silently ignored.
If a block is given, each cookie object is passed to the block.
Available option keywords are below:
:created_at : The creation time of the cookies parsed.
:logger : Logger object useful for debugging
### Compatibility Note for Mechanize::Cookie users
Mechanize::Cookie.parse(uri, set_cookie[, log])
HTTP::Cookie.parse(set_cookie, uri[, :logger => # log])
Tests if target_path is under base_path as described in RFC 6265 5.1.4. base_path must be an absolute path. target_path may be empty, in which case it is treated as the root path.
e.g.
path_match?('/admin/', '/admin/index') == true
path_match?('/admin/', '/Admin/index') == false
path_match?('/admin/', '/admin/') == true
path_match?('/admin/', '/admin') == false
path_match?('/admin', '/admin') == true
path_match?('/admin', '/Admin') == false
path_match?('/admin', '/admins') == false
path_match?('/admin', '/admin/') == true
path_match?('/admin', '/admin/index') == true
Compares the cookie with another. When there are many cookies with the same name for a URL, the value of the smallest must be used.
Tests if it is OK to accept this cookie considering its origin. If either domain or path is missing, raises ArgumentError. If origin is missing, returns true.
Returns a string for use in the Set-Cookie header. If necessary information like a path or domain (when `for_domain` is set) is missing, RuntimeError is raised. It is always the best to set an origin before calling this method.