wp-includes/php-ai-client/src/Providers/Http/HttpTransporter.php:29HTTP transporter implementation using HTTPlug.
$requestFactoryWordPress\AiClientDependencies\Psr\Http\Message\RequestFactoryInterfaceprivate$streamFactoryWordPress\AiClientDependencies\Psr\Http\Message\StreamFactoryInterfaceprivate$clientWordPress\AiClientDependencies\Psr\Http\Client\ClientInterfaceprivateclass HttpTransporter implements HttpTransporterInterface{ /** * @var RequestFactoryInterface PSR-17 request factory. */ private RequestFactoryInterface $requestFactory; /** * @var StreamFactoryInterface PSR-17 stream factory. */ private StreamFactoryInterface $streamFactory; /** * @var ClientInterface PSR-18 HTTP client. */ private ClientInterface $client; /** * Constructor. * * @since 0.1.0 * * @param ClientInterface|null $client PSR-18 HTTP client. * @param RequestFactoryInterface|null $requestFactory PSR-17 request factory. * @param StreamFactoryInterface|null $streamFactory PSR-17 stream factory. */ public function __construct(?ClientInterface $client = null, ?RequestFactoryInterface $requestFactory = null, ?StreamFactoryInterface $streamFactory = null) { $this->client = $client ?: Psr18ClientDiscovery::find(); $this->requestFactory = $requestFactory ?: Psr17FactoryDiscovery::findRequestFactory(); $this->streamFactory = $streamFactory ?: Psr17FactoryDiscovery::findStreamFactory(); } /** * {@inheritDoc} * * @since 0.1.0 * @since 0.2.0 Added optional RequestOptions parameter and ClientWithOptions support. */ public function send(Request $request, ?RequestOptions $options = null): Response { $psr7Request = $this->convertToPsr7Request($request); // Merge request options with parameter options, with parameter options taking precedence $mergedOptions = $this->mergeOptions($request->getOptions(), $options); try { $hasOptions = $mergedOptions !== null; if ($hasOptions && $this->client instanceof ClientWithOptionsInterface) { $psr7Response = $this->client->sendRequestWithOptions($psr7Request, $mergedOptions); } elseif ($hasOptions && $this->isGuzzleClient($this->client)) { $psr7Response = $this->sendWithGuzzle($psr7Request, $mergedOptions); } else { $psr7Response = $this->client->sendRequest($psr7Request); } } catch (\WordPress\AiClientDependencies\Psr\Http\Client\NetworkExceptionInterface $e) { throw NetworkException::fromPsr18NetworkException($psr7Request, $e); } catch (\WordPress\AiClientDependencies\Psr\Http\Client\ClientExceptionInterface $e) { // Handle other PSR-18 client exceptions that are not network-related throw new RuntimeException(sprintf('HTTP client error occurred while sending request to %s: %s', $request->getUri(), $e->getMessage()), 0, $e); } return $this->convertFromPsr7Response($psr7Response); } /** * Merges request options with parameter options taking precedence. * * @since 0.2.0 * * @param RequestOptions|null $requestOptions Options from the Request object. * @param RequestOptions|null $parameterOptions Options passed as method parameter. * @return RequestOptions|null Merged options, or null if both are null. */ private function mergeOptions(?RequestOptions $requestOptions, ?RequestOptions $parameterOptions): ?RequestOptions { // If no options at all, return null if ($requestOptions === null && $parameterOptions === null) { return null; } // If only one set of options exists, return it if ($requestOptions === null) { return $parameterOptions; } if ($parameterOptions === null) { return $requestOptions; } // Both exist, merge them with parameter options taking precedenceIntroduced in 0.1.0. Unchanged from 7.0.4 through 7.1.0.
Signature, return type and hooks compared across 2 parsed releases.
src/wp-includes/php-ai-client/src/Providers/Http/HttpTransporter.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.