mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
Improve documentation.
This commit is contained in:
parent
a0ea64da56
commit
a7575ae3df
5 changed files with 74 additions and 35 deletions
|
|
@ -114,10 +114,10 @@ equivalent using `HTTP::Cookie`:
|
||||||
- `Mechanize::CookieJar#jar`
|
- `Mechanize::CookieJar#jar`
|
||||||
|
|
||||||
There is no direct access to the internal hash in
|
There is no direct access to the internal hash in
|
||||||
`HTTP::CookieJar` since it has introduced an abstract storage
|
`HTTP::CookieJar` since it has introduced an abstract store layer.
|
||||||
layer. If you want to tweak the internals of the hash storage,
|
If you want to tweak the internals of the hash store, try creating
|
||||||
try creating a new storage class referring to the default storage
|
a new store class referring to the default store class
|
||||||
class `HTTP::CookieJar::HashStore`.
|
`HTTP::CookieJar::HashStore`.
|
||||||
|
|
||||||
If you desperately need it you can access it by
|
If you desperately need it you can access it by
|
||||||
`jar.store.instance_variable_get(:@jar)`, but there is no
|
`jar.store.instance_variable_get(:@jar)`, but there is no
|
||||||
|
|
|
||||||
|
|
@ -240,14 +240,14 @@ class HTTP::Cookie
|
||||||
#
|
#
|
||||||
# Available option keywords are below:
|
# Available option keywords are below:
|
||||||
#
|
#
|
||||||
# `origin`
|
# :origin
|
||||||
# : The cookie's origin URI/URL
|
# : The cookie's origin URI/URL
|
||||||
#
|
#
|
||||||
# `date`
|
# :date
|
||||||
# : The base date used for interpreting Max-Age attribute values
|
# : The base date used for interpreting Max-Age attribute values
|
||||||
# instead of the current time
|
# instead of the current time
|
||||||
#
|
#
|
||||||
# `logger`
|
# :logger
|
||||||
# : Logger object useful for debugging
|
# : Logger object useful for debugging
|
||||||
#
|
#
|
||||||
# ### Compatibility Note for Mechanize::Cookie users
|
# ### Compatibility Note for Mechanize::Cookie users
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# :markup: markdown
|
||||||
require 'http/cookie'
|
require 'http/cookie'
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
@ -44,7 +45,7 @@ class HTTP::CookieJar
|
||||||
@store = other.instance_eval { @store.dup }
|
@store = other.instance_eval { @store.dup }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adds a +cookie+ to the jar and return self. If a given cookie has
|
# Adds a cookie to the jar and return self. If a given cookie has
|
||||||
# no domain or path attribute values and the origin is unknown,
|
# no domain or path attribute values and the origin is unknown,
|
||||||
# ArgumentError is raised.
|
# ArgumentError is raised.
|
||||||
#
|
#
|
||||||
|
|
@ -83,7 +84,7 @@ class HTTP::CookieJar
|
||||||
}.sort
|
}.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
# Tests if the jar is empty. If +url+ is given, tests if there is
|
# Tests if the jar is empty. If `url` is given, tests if there is
|
||||||
# no cookie for the URL.
|
# no cookie for the URL.
|
||||||
def empty?(url = nil)
|
def empty?(url = nil)
|
||||||
if url
|
if url
|
||||||
|
|
@ -96,12 +97,12 @@ class HTTP::CookieJar
|
||||||
|
|
||||||
# Iterates over all cookies that are not expired.
|
# Iterates over all cookies that are not expired.
|
||||||
#
|
#
|
||||||
# An optional argument +uri+ specifies a URI/URL indicating the
|
# An optional argument `uri` specifies a URI/URL indicating the
|
||||||
# destination of the cookies being selected. Every cookie yielded
|
# destination of the cookies being selected. Every cookie yielded
|
||||||
# should be good to send to the given URI,
|
# should be good to send to the given URI,
|
||||||
# i.e. cookie.valid_for_uri?(uri) evaluates to true.
|
# i.e. cookie.valid_for_uri?(uri) evaluates to true.
|
||||||
#
|
#
|
||||||
# If (and only if) the +uri+ option is given, last access time of
|
# If (and only if) the `uri` option is given, last access time of
|
||||||
# each cookie is updated to the current time.
|
# each cookie is updated to the current time.
|
||||||
def each(uri = nil, &block)
|
def each(uri = nil, &block)
|
||||||
block_given? or return enum_for(__method__, uri)
|
block_given? or return enum_for(__method__, uri)
|
||||||
|
|
@ -126,16 +127,21 @@ class HTTP::CookieJar
|
||||||
#
|
#
|
||||||
# Available option keywords are below:
|
# Available option keywords are below:
|
||||||
#
|
#
|
||||||
# * +format+
|
# * `:format`
|
||||||
# [<tt>:yaml</tt>]
|
# <dl class="rdoc-list note-list">
|
||||||
# YAML structure (default)
|
# <dt>:yaml</dt>
|
||||||
# [<tt>:cookiestxt</tt>]
|
# <dd>YAML structure (default)</dd>
|
||||||
# Mozilla's cookies.txt format
|
# <dt>:cookiestxt</dt>
|
||||||
# * +session+
|
# <dd>: Mozilla's cookies.txt format</dd>
|
||||||
# [+true+]
|
# </dl>
|
||||||
# Save session cookies as well.
|
#
|
||||||
# [+false+]
|
# * `:session`
|
||||||
# Do not save session cookies. (default)
|
# <dl class="rdoc-list note-list">
|
||||||
|
# <dt>true</dt>
|
||||||
|
# <dd>Save session cookies as well.</dd>
|
||||||
|
# <dt>false</dt>
|
||||||
|
# <dd>Do not save session cookies. (default)</dd>
|
||||||
|
# </dl>
|
||||||
#
|
#
|
||||||
# All options given are passed through to the underlying cookie
|
# All options given are passed through to the underlying cookie
|
||||||
# saver module.
|
# saver module.
|
||||||
|
|
@ -187,11 +193,13 @@ class HTTP::CookieJar
|
||||||
#
|
#
|
||||||
# Available option keywords are below:
|
# Available option keywords are below:
|
||||||
#
|
#
|
||||||
# * +format+
|
# * `:format`
|
||||||
# [<tt>:yaml</tt>]
|
# <dl class="rdoc-list note-list">
|
||||||
# YAML structure (default)
|
# <dt>:yaml</dt>
|
||||||
# [<tt>:cookiestxt</tt>]
|
# <dd>YAML structure (default)</dd>
|
||||||
# Mozilla's cookies.txt format
|
# <dt>:cookiestxt</dt>
|
||||||
|
# <dd>: Mozilla's cookies.txt format</dd>
|
||||||
|
# </dl>
|
||||||
#
|
#
|
||||||
# All options given are passed through to the underlying cookie
|
# All options given are passed through to the underlying cookie
|
||||||
# saver module.
|
# saver module.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ end
|
||||||
# :startdoc:
|
# :startdoc:
|
||||||
|
|
||||||
class HTTP::CookieJar
|
class HTTP::CookieJar
|
||||||
# A store class that uses a hash of hashes.
|
# A store class that uses a hash-based cookie store.
|
||||||
class HashStore < AbstractStore
|
class HashStore < AbstractStore
|
||||||
def default_options
|
def default_options
|
||||||
{
|
{
|
||||||
|
|
@ -17,11 +17,17 @@ class HTTP::CookieJar
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generates a hash based cookie store.
|
||||||
|
#
|
||||||
|
# Available option keywords are as below:
|
||||||
|
#
|
||||||
|
# :gc_threshold
|
||||||
|
# : GC threshold; A GC happens when this many times cookies have
|
||||||
|
# been stored (default: `HTTP::Cookie::MAX_COOKIES_TOTAL / 20`)
|
||||||
def initialize(options = nil)
|
def initialize(options = nil)
|
||||||
super
|
super
|
||||||
|
|
||||||
@jar = {}
|
@jar = {
|
||||||
# {
|
|
||||||
# hostname => {
|
# hostname => {
|
||||||
# path => {
|
# path => {
|
||||||
# name => cookie,
|
# name => cookie,
|
||||||
|
|
@ -30,7 +36,7 @@ class HTTP::CookieJar
|
||||||
# ...
|
# ...
|
||||||
# },
|
# },
|
||||||
# ...
|
# ...
|
||||||
# }
|
}
|
||||||
|
|
||||||
@gc_index = 0
|
@gc_index = 0
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
|
# :markup: markdown
|
||||||
require 'http/cookie_jar'
|
require 'http/cookie_jar'
|
||||||
require 'sqlite3'
|
require 'sqlite3'
|
||||||
|
|
||||||
class HTTP::CookieJar
|
class HTTP::CookieJar
|
||||||
|
# A store class that uses Mozilla compatible SQLite3 database as
|
||||||
|
# backing store.
|
||||||
class MozillaStore < AbstractStore
|
class MozillaStore < AbstractStore
|
||||||
SCHEMA_VERSION = 5
|
SCHEMA_VERSION = 5
|
||||||
|
|
||||||
|
|
@ -26,6 +29,27 @@ class HTTP::CookieJar
|
||||||
appId inBrowserElement
|
appId inBrowserElement
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Generates a Mozilla cookie store. If the file does not exist,
|
||||||
|
# it is created. If it does and its schema is old, it is
|
||||||
|
# automatically upgraded with a new schema keeping the existing
|
||||||
|
# data.
|
||||||
|
#
|
||||||
|
# Available option keywords are as below:
|
||||||
|
#
|
||||||
|
# :filename
|
||||||
|
# : A file name of the SQLite3 database to open. This option is
|
||||||
|
# mandatory.
|
||||||
|
#
|
||||||
|
# :gc_threshold
|
||||||
|
# : GC threshold; A GC happens when this many times cookies have
|
||||||
|
# been stored (default: `HTTP::Cookie::MAX_COOKIES_TOTAL / 20`)
|
||||||
|
#
|
||||||
|
# :app_id
|
||||||
|
# : application ID (default: `0`) to have per application jar.
|
||||||
|
#
|
||||||
|
# :in_browser_element
|
||||||
|
# : a flag to tell if cookies are stored in an in browser
|
||||||
|
# element. (default: `false`)
|
||||||
def initialize(options = nil)
|
def initialize(options = nil)
|
||||||
super
|
super
|
||||||
|
|
||||||
|
|
@ -39,6 +63,7 @@ class HTTP::CookieJar
|
||||||
@gc_index = 0
|
@gc_index = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the schema version of the database.
|
||||||
def schema_version
|
def schema_version
|
||||||
@schema_version ||= @db.execute("PRAGMA user_version").first[0]
|
@schema_version ||= @db.execute("PRAGMA user_version").first[0]
|
||||||
rescue SQLite3::SQLException
|
rescue SQLite3::SQLException
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue