Skip to content

Commit 988d8e9

Browse files
committed
minor #14195 [HttpClient] Providing additional options to CurlHttpClient section (pizzaminded)
This PR was squashed before being merged into the master branch. Discussion ---------- [HttpClient] Providing additional options to CurlHttpClient section Documentation for symfony/symfony#38026 PR. Commits ------- 729c7df [HttpClient] Providing additional options to CurlHttpClient section
2 parents fc9ab91 + 729c7df commit 988d8e9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

http_client.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,39 @@ When using this component in a full-stack Symfony application, this behavior is
728728
not configurable and cURL will be used automatically if the cURL PHP extension
729729
is installed and enabled. Otherwise, the native PHP streams will be used.
730730

731+
Providing Additional Options to CurlHttpClient
732+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
733+
734+
It is possible to provide additional cURL options to ``CurlHttpClient``. PHP exposes
735+
a lot of `cURL options`_ that can be passed to ``curl_setopt`` function, but only some
736+
of them are used in ``CurlHttpClient`` in favor of bigger component portability.
737+
738+
To provide cURL-related parameters to request, add an ``extra.curl`` option in your
739+
configuration::
740+
741+
use Symfony\Component\HttpClient\CurlHttpClient;
742+
743+
$client = new CurlHttpClient();
744+
745+
$client->request('POST', 'https://...', [
746+
// ...
747+
'extra' => [
748+
'curl' => [
749+
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V6
750+
]
751+
]
752+
]);
753+
754+
755+
This option is available only when using ``CurlHttpClient``, other clients will ignore these options.
756+
757+
.. note::
758+
759+
Some cURL options are impossible to override due of. e.g Thread Safety or existing options in
760+
``$options`` configuration which will set given attributes internally. An exception will be
761+
thrown while overriding them.
762+
763+
731764
HTTP/2 Support
732765
~~~~~~~~~~~~~~
733766

@@ -1391,3 +1424,4 @@ However, using ``MockResponse`` allows simulating chunked responses and timeouts
13911424
.. _`Symfony Contracts`: https://github.com/symfony/contracts
13921425
.. _`libcurl`: https://curl.haxx.se/libcurl/
13931426
.. _`amphp/http-client`: https://packagist.org/packages/amphp/http-client
1427+
.. _`cURL options`: https://www.php.net/manual/en/function.curl-setopt.php

0 commit comments

Comments
 (0)