Skip to content

[HttpClient] Providing additional options to CurlHttpClient section #14195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions http_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,39 @@ When using this component in a full-stack Symfony application, this behavior is
not configurable and cURL will be used automatically if the cURL PHP extension
is installed and enabled. Otherwise, the native PHP streams will be used.

Providing Additional Options to CurlHttpClient
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It is possible to provide additional cURL options to ``CurlHttpClient``. PHP exposes
a lot of `cURL options`_ that can be passed to ``curl_setopt`` function, but only some
of them are used in ``CurlHttpClient`` in favor of bigger component portability.

To provide cURL-related parameters to request, add an ``extra.curl`` option in your
configuration::

use Symfony\Component\HttpClient\CurlHttpClient;

$client = new CurlHttpClient();

$client->request('POST', 'https://...', [
// ...
'extra' => [
'curl' => [
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V6
]
]
]);


This option is available only when using ``CurlHttpClient``, other clients will ignore these options.

.. note::

Some cURL options are impossible to override due of. e.g Thread Safety or existing options in
``$options`` configuration which will set given attributes internally. An exception will be
thrown while overriding them.


HTTP/2 Support
~~~~~~~~~~~~~~

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