Skip to content

Commit 1aa9a11

Browse files
[HttpClient] add HttpClient::createForBaseUri()
1 parent 211c651 commit 1aa9a11

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/HttpClient/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ CHANGELOG
44
4.4.0
55
-----
66

7-
* added `StreamWrapper`
7+
* added `HttpClient::createForBaseUri()`
88
* added `HttplugClient` with support for sync and async requests
99
* added `max_duration` option
1010
* added support for NTLM authentication
11+
* added `StreamWrapper` to cast any `ResponseInterface` instances to PHP streams.
1112
* added `$response->toStream()` to cast responses to regular PHP streams
1213
* made `Psr18Client` implement relevant PSR-17 factories and have streaming responses
1314
* added `TraceableHttpClient`, `HttpClientDataCollector` and `HttpClientPass` to integrate with the web profiler

src/Symfony/Component/HttpClient/HttpClient.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,14 @@ public static function create(array $defaultOptions = [], int $maxHostConnection
3939

4040
return new NativeHttpClient($defaultOptions, $maxHostConnections);
4141
}
42+
43+
/**
44+
* Creates a client that adds options (e.g. authentication headers) only when the request URL matches the provided base URI.
45+
*/
46+
public static function createForBaseUri(string $baseUri, array $defaultOptions = [], int $maxHostConnections = 6, int $maxPendingPushes = 50): HttpClientInterface
47+
{
48+
$client = self::create([], $maxHostConnections, $maxPendingPushes);
49+
50+
return ScopingHttpClient::forBaseUri($client, $baseUri, $defaultOptions);
51+
}
4252
}

0 commit comments

Comments
 (0)
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