1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-12 03:24:26 +01:00

Fixing cookies docs. Closes #1072

This commit is contained in:
Michael Dowling 2015-05-25 16:10:05 -07:00
parent 1d085bb50a
commit b158770ee6
2 changed files with 19 additions and 25 deletions

View File

@ -386,31 +386,24 @@ Cookies
=======
Guzzle can maintain a cookie session for you if instructed using the
``cookies`` request option.
- Set to ``true`` to use a shared cookie session associated with the client.
- Pass an associative array containing cookies to send in the request and start
a new cookie session.
- Set to a ``GuzzleHttp\Subscriber\CookieJar\CookieJarInterface`` object to use
an existing cookie jar.
``cookies`` request option. When sending a request, the ``cookies`` option
must be set an an instance of ``GuzzleHttp\Subscriber\CookieJar\CookieJarInterface``.
.. code-block:: php
// Use a shared client cookie jar
$r = $client->get('http://httpbin.org/cookies', ['cookies' => true]);
// Use an array of cookies
$r = $client->get('http://httpbin.org/cookies', [
'cookies' => [
'foo' => 'bar',
'baz' => 'qux',
]
]);
// Use a specific cookie jar
$jar = new \GuzzleHttp\Cookie\CookieJar;
$r = $client->get('http://httpbin.org/cookies', ['cookies' => $jar]);
You can set ``cookies`` to ``true`` in a client constructor if you would like
to use a shared cookie jar for all requests.
.. code-block:: php
// Use a shared client cookie jar
$client = new \GuzzleHttp\Client(['cookies' => true]);
$r = $client->get('http://httpbin.org/cookies');
Redirects
=========

View File

@ -190,16 +190,12 @@ cookies
:Summary: Specifies whether or not cookies are used in a request or what cookie
jar to use or what cookies to send.
:Types:
- bool
- ``GuzzleHttp\Cookie\CookieJarInterface``
:Types: ``GuzzleHttp\Cookie\CookieJarInterface``
:Default: None
:Constant: ``GuzzleHttp\RequestOptions::COOKIES``
When creating a client, you can set the default cookie option to ``true``
to use a shared cookie session associated with the client. Othewise, you
must specify the cookies option as a ``GuzzleHttp\Cookie\CookieJarInterface``
or ``false``.
You must specify the cookies option as a
``GuzzleHttp\Cookie\CookieJarInterface`` or ``false``.
.. code-block:: php
@ -213,6 +209,11 @@ or ``false``.
by default when a client is created with no handler, and is added by
default when creating a handler with ``GuzzleHttp\default_handler``.
.. tip::
When creating a client, you can set the default cookie option to ``true``
to use a shared cookie session associated with the client.
.. _connect_timeout-option: