Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cookie share example in docs (and make a bit verbose) #817

Merged
merged 1 commit into from
Mar 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions docs/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ parameter of :class:`ClientSession` constructor::
assert await resp.json() == {"cookies":
{"cookies_are": "working"}}

.. note::
``httpbin.org/cookies`` endpoint returns request cookies
in JSON-encoded body.
To access session cookies see :attr:`ClientSession.cookies`.


More complicated POST requests
------------------------------
Expand Down Expand Up @@ -362,19 +367,21 @@ Keep-Alive, connection pooling and cookie sharing
between multiple requests::

async with aiohttp.ClientSession() as session:
await session.post(
'http://httpbin.org/cookies/set/my_cookie/my_value')
await session.get(
'http://httpbin.org/cookies/set?my_cookie=my_value')
assert session.cookies['my_cookie'].value == 'my_value'
async with session.get('http://httpbin.org/cookies') as r:
json = await r.json()
assert json['cookies']['my_cookie'] == 'my_value'
json_body = await r.json()
assert json_body['cookies']['my_cookie'] == 'my_value'

You also can set default headers for all session requests::

async with aiohttp.ClientSession(
headers={"Authorization": "Basic bG9naW46cGFzcw=="}) as session:
async with s.get("http://httpbin.org/headers") as r:
json = yield from r.json()
assert json['headers']['Authorization'] == 'Basic bG9naW46cGFzcw=='
async with session.get("http://httpbin.org/headers") as r:
json_body = await r.json()
assert json_body['headers']['Authorization'] == \
'Basic bG9naW46cGFzcw=='

:class:`~aiohttp.ClientSession` supports keep-alive requests
and connection pooling out-of-the-box.
Expand Down