Skip to content

Commit a447b04

Browse files
committed
feature #11632 [HttpClient] add note about getInfo(debug) (nicolas-grekas, weaverryan)
This PR was merged into the 4.3 branch. Discussion ---------- [HttpClient] add note about getInfo(debug) As implemented in symfony/symfony#31641 Commits ------- 0278830 fixing syntax b05f9ca [HttpClient] add note about getInfo(debug)
2 parents 779bb84 + 0278830 commit a447b04

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
@@ -265,6 +265,10 @@ following methods::
265265
// you can get individual info too
266266
$startTime = $response->getInfo('start_time');
267267

268+
.. tip::
269+
270+
Call ``$response->getInfo('debug')`` to get detailed logs about the HTTP transaction.
271+
268272
.. _http-client-streaming-responses:
269273

270274
Streaming Responses
@@ -316,17 +320,25 @@ When the HTTP status code of the response is in the 300-599 range (i.e. 3xx,
316320
Caching Requests and Responses
317321
------------------------------
318322

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

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

331343
Scoping Client
332344
--------------

0 commit comments

Comments
 (0)