From 1aa9a118d6e9f1eda4ffdc0c9aef4eac51b81b91 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 13 Oct 2019 19:51:09 +0200 Subject: [PATCH] [HttpClient] add HttpClient::createForBaseUri() --- src/Symfony/Component/HttpClient/CHANGELOG.md | 3 ++- src/Symfony/Component/HttpClient/HttpClient.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpClient/CHANGELOG.md b/src/Symfony/Component/HttpClient/CHANGELOG.md index c36aeb65ce6ca..bddd592b3b8a6 100644 --- a/src/Symfony/Component/HttpClient/CHANGELOG.md +++ b/src/Symfony/Component/HttpClient/CHANGELOG.md @@ -4,10 +4,11 @@ CHANGELOG 4.4.0 ----- - * added `StreamWrapper` + * added `HttpClient::createForBaseUri()` * added `HttplugClient` with support for sync and async requests * added `max_duration` option * added support for NTLM authentication + * added `StreamWrapper` to cast any `ResponseInterface` instances to PHP streams. * added `$response->toStream()` to cast responses to regular PHP streams * made `Psr18Client` implement relevant PSR-17 factories and have streaming responses * added `TraceableHttpClient`, `HttpClientDataCollector` and `HttpClientPass` to integrate with the web profiler diff --git a/src/Symfony/Component/HttpClient/HttpClient.php b/src/Symfony/Component/HttpClient/HttpClient.php index 90e71c2437922..3eb3a4c8849ea 100644 --- a/src/Symfony/Component/HttpClient/HttpClient.php +++ b/src/Symfony/Component/HttpClient/HttpClient.php @@ -39,4 +39,14 @@ public static function create(array $defaultOptions = [], int $maxHostConnection return new NativeHttpClient($defaultOptions, $maxHostConnections); } + + /** + * Creates a client that adds options (e.g. authentication headers) only when the request URL matches the provided base URI. + */ + public static function createForBaseUri(string $baseUri, array $defaultOptions = [], int $maxHostConnections = 6, int $maxPendingPushes = 50): HttpClientInterface + { + $client = self::create([], $maxHostConnections, $maxPendingPushes); + + return ScopingHttpClient::forBaseUri($client, $baseUri, $defaultOptions); + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy