mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
Update examples.
This commit is contained in:
parent
28458101b6
commit
cd9571615a
1 changed files with 15 additions and 7 deletions
22
README.md
22
README.md
|
|
@ -38,7 +38,7 @@ Or install it yourself as:
|
||||||
jar.parse(set_cookie_header_value, uri)
|
jar.parse(set_cookie_header_value, uri)
|
||||||
|
|
||||||
# Get the value for the Cookie field of a request header
|
# Get the value for the Cookie field of a request header
|
||||||
cookie_header_value = jar.cookies(uri).join(', ')
|
cookie_header_value = HTTP::Cookie.cookie_value(jar.cookies(uri))
|
||||||
|
|
||||||
# Save to a file
|
# Save to a file
|
||||||
jar.save(filename)
|
jar.save(filename)
|
||||||
|
|
@ -54,23 +54,31 @@ Or install it yourself as:
|
||||||
jar.parse(set_cookie_header_value, uri)
|
jar.parse(set_cookie_header_value, uri)
|
||||||
|
|
||||||
# Get the value for the Cookie field of a request header
|
# Get the value for the Cookie field of a request header
|
||||||
cookie_header_value = jar.cookies(uri).join(', ')
|
cookie_header_value = HTTP::Cookie.cookie_value(jar.cookies(uri))
|
||||||
|
|
||||||
# There is no need for load & save.
|
# There is no need for load & save in this backend.
|
||||||
|
|
||||||
|
|
||||||
########################
|
########################
|
||||||
# Server side example
|
# Server side example
|
||||||
########################
|
########################
|
||||||
|
|
||||||
# Generate a cookie
|
# Generate a domain cookie
|
||||||
cookies = HTTP::Cookie.new("uid", "a12345", domain: 'example.org',
|
cookie2 = HTTP::Cookie.new("uid", "u12345", domain: 'example.org',
|
||||||
for_domain: true,
|
for_domain: true,
|
||||||
path: '/',
|
path: '/',
|
||||||
max_age: 7*86400)
|
max_age: 7*86400)
|
||||||
|
|
||||||
# Get the value for the Set-Cookie field of a response header
|
# Generate a host-only cookie
|
||||||
set_cookie_header_value = cookies.set_cookie_value(my_url)
|
cookie1 = HTTP::Cookie.new("aid", "a12345", origin: my_url,
|
||||||
|
path: '/',
|
||||||
|
max_age: 7*86400)
|
||||||
|
|
||||||
|
# Set the Set-Cookie response header value
|
||||||
|
header['Set-Cookie'] = [
|
||||||
|
cookie1.set_cookie_value,
|
||||||
|
cookie2.set_cookie_value,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
## Incompatibilities with Mechanize::Cookie/CookieJar
|
## Incompatibilities with Mechanize::Cookie/CookieJar
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue