@@ -833,16 +833,62 @@ as a service named ``http_client`` or using the autowiring alias
833
833
834
834
This service can be configured using ``framework.http_client.default_options ``:
835
835
836
- .. code -block :: yaml
836
+ .. configuration -block ::
837
837
838
- # config/packages/framework.yaml
839
- framework :
840
- # ...
841
- http_client :
842
- max_host_connections : 10
843
- default_options :
844
- headers : { 'X-Powered-By': 'ACME App' }
845
- max_redirects : 7
838
+ .. code-block :: yaml
839
+
840
+ # config/packages/framework.yaml
841
+ framework :
842
+ # ...
843
+ http_client :
844
+ max_host_connections : 10
845
+ default_options :
846
+ headers : { 'X-Powered-By': 'ACME App' }
847
+ max_redirects : 7
848
+
849
+ .. code-block :: xml
850
+
851
+ <!-- config/packages/framework.xml -->
852
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
853
+ <container xmlns =" http://symfony.com/schema/dic/services"
854
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
855
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
856
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
857
+ https://symfony.com/schema/dic/services/services-1.0.xsd
858
+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
859
+
860
+ <framework : config >
861
+ <framework : http-client max-host-connections =" 10" >
862
+ <framework : default-options max-redirects =" 7" >
863
+ <framework : header name =" X-Powered-By" >ACME App</framework : header >
864
+ </framework : default-options >
865
+ </framework : http-client >
866
+ </framework : config >
867
+ </container >
868
+
869
+ .. code-block :: php
870
+
871
+ // config/packages/framework.php
872
+ $container->loadFromExtension('framework', [
873
+ 'http_client' => [
874
+ 'max_host_connections' => 10,
875
+ 'default_options' => [
876
+ 'headers' => [
877
+ 'X-Powered-By' => 'ACME App',
878
+ ],
879
+ 'max_redirects' => 7,
880
+ ],
881
+ ],
882
+ ]);
883
+
884
+ .. code-block :: php-standalone
885
+
886
+ $client = HttpClient::create([
887
+ 'headers' => [
888
+ 'X-Powered-By' => 'ACME App',
889
+ ],
890
+ 'max_redirects' => 7,
891
+ ], 10);
846
892
847
893
.. _reference-http-client-scoped-clients :
848
894
@@ -851,16 +897,57 @@ service name defined as a key under ``scoped_clients``. Scoped clients inherit
851
897
the default options defined for the ``http_client `` service. You can override
852
898
these options and can define a few others:
853
899
854
- .. code -block :: yaml
900
+ .. configuration -block ::
855
901
856
- # config/packages/framework.yaml
857
- framework :
858
- # ...
859
- http_client :
860
- scoped_clients :
861
- my_api.client :
862
- auth_bearer : secret_bearer_token
863
- # ...
902
+ .. code-block :: yaml
903
+
904
+ # config/packages/framework.yaml
905
+ framework :
906
+ # ...
907
+ http_client :
908
+ scoped_clients :
909
+ my_api.client :
910
+ auth_bearer : secret_bearer_token
911
+ # ...
912
+
913
+ .. code-block :: xml
914
+
915
+ <!-- config/packages/framework.xml -->
916
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
917
+ <container xmlns =" http://symfony.com/schema/dic/services"
918
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
A92E
span>
919
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
920
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
921
+ https://symfony.com/schema/dic/services/services-1.0.xsd
922
+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
923
+
924
+ <framework : config >
925
+ <framework : http-client >
926
+ <framework : scoped-client name =" my_api.client" auth-bearer =" secret_bearer_token" />
927
+ </framework : http-client >
928
+ </framework : config >
929
+ </container >
930
+
931
+ .. code-block :: php
932
+
933
+ // config/packages/framework.php
934
+ $container->loadFromExtension('framework', [
935
+ 'http_client' => [
936
+ 'scoped_clients' => [
937
+ 'my_api.client' => [
938
+ 'auth_bearer' => 'secret_bearer_token',
939
+ // ...
940
+ ],
941
+ ],
942
+ ],
943
+ ]);
944
+
945
+ .. code-block :: php-standalone
946
+
947
+ $client = HttpClient::createForBaseUri('https://...', [
948
+ 'auth_bearer' => 'secret_bearer_token',
949
+ // ...
950
+ ]);
864
951
865
952
Options defined for scoped clients apply only to URLs that match either their
866
953
`base_uri `_ or the `scope `_ option when it is defined. Non-matching URLs always
0 commit comments