@@ -784,16 +784,62 @@ as a service named ``http_client`` or using the autowiring alias
784
784
785
785
This service can be configured using ``framework.http_client.default_options ``:
786
786
787
- .. code -block :: yaml
787
+ .. configuration -block ::
788
788
789
- # config/packages/framework.yaml
790
- framework :
791
- # ...
792
- http_client :
793
- max_host_connections : 10
794
- default_options :
795
- headers : { 'X-Powered-By': 'ACME App' }
796
- max_redirects : 7
789
+ .. code-block :: yaml
790
+
791
+ # config/packages/framework.yaml
792
+ framework :
793
+ # ...
794
+ http_client :
795
+ max_host_connections : 10
796
+ default_options :
797
+ headers : { 'X-Powered-By': 'ACME App' }
798
+ max_redirects : 7
799
+
800
+ .. code-block :: xml
801
+
802
+ <!-- config/packages/framework.xml -->
803
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
804
+ <container xmlns =" http://symfony.com/schema/dic/services"
805
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
806
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
807
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
808
+ https://symfony.com/schema/dic/services/services-1.0.xsd
809
+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
810
+
811
+ <framework : config >
812
+ <framework : http-client max-host-connections =" 10" >
813
+ <framework : default-options max-redirects =" 7" >
814
+ <framework : header name =" X-Powered-By" >ACME App</framework : header >
815
+ </framework : default-options >
816
+ </framework : http-client >
817
+ </framework : config >
818
+ </container >
819
+
820
+ .. code-block :: php
821
+
822
+ // config/packages/framework.php
823
+ $container->loadFromExtension('framework', [
824
+ 'http_client' => [
825
+ 'max_host_connections' => 10,
826
+ 'default_options' => [
827
+ 'headers' => [
828
+ 'X-Powered-By' => 'ACME App',
829
+ ],
830
+ 'max_redirects' => 7,
831
+ ],
832
+ ],
833
+ ]);
834
+
835
+ .. code-block :: php-standalone
836
+
837
+ $client = HttpClient::create([
838
+ 'headers' => [
839
+ 'X-Powered-By' => 'ACME App',
840
+ ],
841
+ 'max_redirects' => 7,
842
+ ], 10);
797
843
798
844
.. _reference-http-client-scoped-clients :
799
845
@@ -802,16 +848,57 @@ service name defined as a key under ``scoped_clients``. Scoped clients inherit
802
848
the default options defined for the ``http_client `` service. You can override
803
849
these options and can define a few others:
804
850
805
- .. code -block :: yaml
851
+ .. configuration -block ::
806
852
807
- # config/packages/framework.yaml
808
- framework :
809
- # ...
810
- http_client :
811
- scoped_clients :
812
- my_api.client :
813
- auth_bearer : secret_bearer_token
814
- # ...
853
+ .. code-block :: yaml
854
+
855
+ # config/packages/framework.yaml
856
+ framework :
857
+ # ...
858
+ http_client :
859
+ scoped_clients :
860
+ my_api.client :
861
+ auth_bearer : secret_bearer_token
862
+ # ...
863
+
864
+ .. code-block :: xml
865
+
866
+ <!-- config/packages/framework.xml -->
867
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
868
+ <container xmlns =" http://symfony.com/schema/dic/services"
869
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
870
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
871
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
872
+ https://symfony.com/schema/dic/services/services-1.0.xsd
873
+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
874
+
875
+ <framework : config >
876
+ <framework : http-client >
877
+ <framework : scoped-client name =" my_api.client" auth-bearer =" secret_bearer_token" />
878
+ </framework : http-client >
879
+ </framework : config >
880
+ </container >
881
+
882
+ .. code-block :: php
883
+
884
+ // config/packages/framework.php
885
+ $container->loadFromExtension('framework', [
886
+ 'http_client' => [
887
+ 'scoped_clients' => [
888
+ 'my_api.client' => [
889
+ 'auth_bearer' => 'secret_bearer_token',
890
+ // ...
891
+ ],
892
+ ],
893
+ ],
894
+ ]);
895
+
896
+ .. code-block :: php-standalone
897
+
898
+ $client = HttpClient::createForBaseUri('https://...', [
899
+ 'auth_bearer' => 'secret_bearer_token',
900
+ // ...
901
+ ]);
815
902
816
903
Options defined for scoped clients apply only to URLs that match either their
817
904
`base_uri `_ or the `scope `_ option when it is defined. Non-matching URLs always
0 commit comments