mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
Update README.md.
This commit is contained in:
parent
ef1f759e9d
commit
9c7d563da5
1 changed files with 24 additions and 6 deletions
30
README.md
30
README.md
|
|
@ -25,7 +25,7 @@ Or install it yourself as:
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
########################
|
########################
|
||||||
# Client side example
|
# Client side example 1
|
||||||
########################
|
########################
|
||||||
|
|
||||||
# Initialize a cookie jar
|
# Initialize a cookie jar
|
||||||
|
|
@ -43,6 +43,21 @@ Or install it yourself as:
|
||||||
# Save to a file
|
# Save to a file
|
||||||
jar.save(filename)
|
jar.save(filename)
|
||||||
|
|
||||||
|
########################
|
||||||
|
# Client side example 2
|
||||||
|
########################
|
||||||
|
|
||||||
|
# Initialize a cookie jar using a Mozilla compatible SQLite3 backend
|
||||||
|
jar = HTTP::CookieJar.new(store: :mozilla, filename: 'cookies.sqlite')
|
||||||
|
|
||||||
|
# Store received cookies
|
||||||
|
jar.parse(set_cookie_header_value, uri)
|
||||||
|
|
||||||
|
# Get the value for the Cookie field of a request header
|
||||||
|
cookie_header_value = jar.cookies(uri).join(', ')
|
||||||
|
|
||||||
|
# There is no need for load & save.
|
||||||
|
|
||||||
|
|
||||||
########################
|
########################
|
||||||
# Server side example
|
# Server side example
|
||||||
|
|
@ -75,14 +90,17 @@ equivalent using HTTP::Cookie:
|
||||||
|
|
||||||
# after
|
# after
|
||||||
cookies1 = HTTP::Cookie.parse(set_cookie1, uri_or_url)
|
cookies1 = HTTP::Cookie.parse(set_cookie1, uri_or_url)
|
||||||
cookies2 = HTTP::Cookie.parse(set_cookie2, uri_or_url, :logger => log)
|
cookies2 = HTTP::Cookie.parse(set_cookie2, uri_or_url, logger: log)
|
||||||
|
# or you can directly store parsed cookies in your jar
|
||||||
|
jar.parse(set_cookie1, uri_or_url)
|
||||||
|
jar.parse(set_cookie1, uri_or_url, logger: log)
|
||||||
|
|
||||||
- Mechanize::Cookie#version, #version=
|
- Mechanize::Cookie#version, #version=
|
||||||
|
|
||||||
There is no longer a sense of version in HTTP cookie. The only
|
There is no longer a sense of version in the HTTP cookie
|
||||||
version number that has ever been defined was zero, and there will
|
specification. The only version number ever defined was zero, and
|
||||||
be no other version since the version attribute has been removed
|
there will be no other version defined since the version attribute
|
||||||
in RFC 6265.
|
has been removed in RFC 6265.
|
||||||
|
|
||||||
- Mechanize::Cookie#comment, #comment=
|
- Mechanize::Cookie#comment, #comment=
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue