WordPress\AiClient\Providers\Http

HttpTransporter::sendpublicWP 0.1.0

{@inheritDoc}

Method of the class: HttpTransporter{}

No Hooks.

Returns

null. Nothing (null).

Usage

$HttpTransporter = new HttpTransporter();
$HttpTransporter->send( $request, ?RequestOptions $options ): Response;
$request(Request) (required)
.
?RequestOptions $options
.
Default: null

Changelog

Since 0.1.0 Introduced.
Since 0.2.0 Added optional RequestOptions parameter and ClientWithOptions support.

HttpTransporter::send() code WP 7.0

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);
}