Skip to content

Commit df6db26

Browse files
committed
Merge branch '4.4'
* 4.4: fixing syntax [HttpClient] add note about getInfo(debug)
2 parents 1edf64c + a447b04 commit df6db26

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

components/http_client.rst

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ following methods::
261261
// you can get individual info too
262262
$startTime = $response->getInfo('start_time');
263263

264+
.. tip::
265+
266+
Call ``$response->getInfo('debug')`` to get detailed logs about the HTTP transaction.
267+
264268
.. _http-client-streaming-responses:
265269

266270
Streaming Responses
@@ -312,17 +316,25 @@ When the HTTP status code of the response is in the 300-599 range (i.e. 3xx,
312316
Caching Requests and Responses
313317
------------------------------
314318

315-
This component provides a special HTTP client via the
316-
:class:`Symfony\\Component\\HttpClient\\CachingHttpClient` class to cache
317-
requests and their responses. The actual HTTP caching is implemented using the
318-
:doc:`HttpKernel component </components/http_kernel>`, so make sure it's
319-
installed in your application.
319+
This component provides a :class:`Symfony\\Component\\HttpClient\\CachingHttpClient`
320+
decorator that allows caching responses and serving them from the local storage
321+
for next requests. The implementation leverages the
322+
:class:`Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache` class under the hood
323+
so that the :doc:`HttpKernel component </components/http_kernel>` needs to be
324+
installed in your application::
320325

321-
..
322-
.. TODO:
323-
.. Show some example of caching requests+responses
324-
..
325-
..
326+
use Symfony\Component\HttpClient\HttpClient;
327+
use Symfony\Component\HttpClient\CachingHttpClient;
328+
use Symfony\Component\HttpKernel\HttpCache\Store;
329+
330+
$store = new Store('/path/to/cache/storage/');
331+
$client = HttpClient::create();
332+
$client = new CachingHttpClient($client, $store);
333+
334+
// this won't hit the network if the resource is already in the cache
335+
$response = $client->request('GET', 'https://example.com/cacheable-resource');
336+
337+
``CachingHttpClient`` accepts a third argument to set the options of the ``HttpCache``.
326338

327339
Scoping Client
328340
--------------

0 commit comments

Comments
 (0)