Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb05f9ca

Browse files
[HttpClient] add note about getInfo(debug)
1 parent779bb84 commitb05f9ca

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

‎components/http_client.rst‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ following methods::
265265
// you can get individual info too
266266
$startTime = $response->getInfo('start_time');
267267

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

270273
Streaming Responses
@@ -316,17 +319,25 @@ When the HTTP status code of the response is in the 300-599 range (i.e. 3xx,
316319
Caching Requests and Responses
317320
------------------------------
318321

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.
322+
This component provides a:class:`Symfony\\Component\\HttpClient\\CachingHttpClient`
323+
decorator that allows caching responses and serving them from the local storage
324+
for next requests. The implementation leverages the
325+
:class:`Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache` class under the hood
326+
so that the:doc:`HttpKernel component</components/http_kernel>` needs to be
327+
installed in your application::
324328

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

331342
Scoping Client
332343
--------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp