@@ -751,16 +751,62 @@ as a service named ``http_client`` or using the autowiring alias
751751
752752This service can be configured using ``framework.http_client.default_options ``:
753753
754- .. code-block :: yaml
754+ .. configuration-block ::
755+
756+ .. code-block :: yaml
757+
758+ # config/packages/framework.yaml
759+ framework :
760+ # ...
761+ http_client :
762+ max_host_connections : 10
763+ default_options :
764+ headers : { 'X-Powered-By': 'ACME App' }
765+ max_redirects : 7
766+
767+ .. code-block :: xml
768+
769+ <!-- config/packages/framework.xml -->
770+ <?xml version =" 1.0" encoding =" UTF-8" ?>
771+ <container xmlns =" http://symfony.com/schema/dic/services"
772+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
773+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
774+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
775+ https://symfony.com/schema/dic/services/services-1.0.xsd
776+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
755777
756- # config/packages/framework.yaml
757- framework :
758- # ...
759- http_client :
760- max_host_connections : 10
761- default_options :
762- headers : { 'X-Powered-By': 'ACME App' }
763- max_redirects : 7
778+ <framework : config >
779+ <framework : http-client max-host-connections =" 10" >
780+ <framework : default-options max-redirects =" 7" >
781+ <framework : header name =" X-Powered-By" >ACME App</framework : header >
782+ </framework : default-options >
783+ </framework : http-client >
784+ </framework : config >
785+ </container >
786+
787+ .. code-block :: php
788+
789+ // config/packages/framework.php
790+ $container->loadFromExtension('framework', [
791+ 'http_client' => [
792+ 'max_host_connections' => 10,
793+ 'default_options' => [
794+ 'headers' => [
795+ 'X-Powered-By' => 'ACME App',
796+ ],
797+ 'max_redirects' => 7,
798+ ],
799+ ],
800+ ]);
801+
802+ .. code-block :: php-standalone
803+
804+ $client = HttpClient::create([
805+ 'headers' => [
806+ 'X-Powered-By' => 'ACME App',
807+ ],
808+ 'max_redirects' => 7,
809+ ], 10);
764810
765811 .. _reference-http-client-scoped-clients :
766812
@@ -769,16 +815,57 @@ service name defined as a key under ``scoped_clients``. Scoped clients inherit
769815the default options defined for the ``http_client `` service. You can override
770816these options and can define a few others:
771817
772- .. code-block :: yaml
818+ .. configuration-block ::
819+
820+ .. code-block :: yaml
773821
774- # config/packages/framework.yaml
775- framework :
776- # ...
777- http_client :
778- scoped_clients :
779- my_api.client :
780- auth_bearer : secret_bearer_token
781- # ...
822+ # config/packages/framework.yaml
823+ framework :
824+ # ...
825+ http_client :
826+ scoped_clients :
827+ my_api.client :
828+ auth_bearer : secret_bearer_token
829+ # ...
830+
831+ .. code-block :: xml
832+
833+ <!-- config/packages/framework.xml -->
834+ <?xml version =" 1.0" encoding =" UTF-8" ?>
835+ <container xmlns =" http://symfony.com/schema/dic/services"
836+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
837+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
838+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
839+ https://symfony.com/schema/dic/services/services-1.0.xsd
840+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
841+
842+ <framework : config >
843+ <framework : http-client >
844+ <framework : scoped-client name =" my_api.client" auth-bearer =" secret_bearer_token" />
845+ </framework : http-client >
846+ </framework : config >
847+ </container >
848+
849+ .. code-block :: php
850+
851+ // config/packages/framework.php
852+ $container->loadFromExtension('framework', [
853+ 'http_client' => [
854+ 'scoped_clients' => [
855+ 'my_api.client' => [
856+ 'auth_bearer' => 'secret_bearer_token',
857+ // ...
858+ ],
859+ ],
860+ ],
861+ ]);
862+
863+ .. code-block :: php-standalone
864+
865+ $client = HttpClient::createForBaseUri('https://...', [
866+ 'auth_bearer' => 'secret_bearer_token',
867+ // ...
868+ ]);
782869
783870 Options defined for scoped clients apply only to URLs that match either their
784871`base_uri `_ or the `scope `_ option when it is defined. Non-matching URLs always
0 commit comments