diff --git a/src/Kernel/Traits/InteractWithHttpClient.php b/src/Kernel/Traits/InteractWithHttpClient.php index aa914a9ce..518b77814 100644 --- a/src/Kernel/Traits/InteractWithHttpClient.php +++ b/src/Kernel/Traits/InteractWithHttpClient.php @@ -5,10 +5,11 @@ namespace EasyWeChat\Kernel\Traits; use EasyWeChat\Kernel\HttpClient\RequestUtil; +use EasyWeChat\Kernel\Support\Arr; use Psr\Log\LoggerAwareInterface; use Symfony\Component\HttpClient\HttpClient; +use Symfony\Component\HttpClient\ScopingHttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; - use function property_exists; trait InteractWithHttpClient @@ -39,7 +40,18 @@ public function setHttpClient(HttpClientInterface $httpClient): static protected function createHttpClient(): HttpClientInterface { - return HttpClient::create(RequestUtil::formatDefaultOptions($this->getHttpClientDefaultOptions())); + $options = $this->getHttpClientDefaultOptions(); + + $optionsByRegexp = Arr::get($options, 'options_by_regexp', []); + unset($options['options_by_regexp']); + + $client = HttpClient::create(RequestUtil::formatDefaultOptions($options)); + + if (! empty($optionsByRegexp)) { + $client = new ScopingHttpClient($client, $optionsByRegexp); + } + + return $client; } /**