Skip to content

Commit b68794f

Browse files
[HttpClient] add HttpClient::createForBaseUri()
1 parent 4eaa6ef commit b68794f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

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)