WordPress\AiClient\Providers\Http
HttpTransporter::send
{@inheritDoc}
Метод класса: HttpTransporter{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$HttpTransporter = new HttpTransporter(); $HttpTransporter->send( $request, ?RequestOptions $options ): Response;
- $request(Request) (обязательный)
- .
- ?RequestOptions $options
- .
По умолчанию:null
Список изменений
| С версии 0.1.0 | Введена. |
| С версии 0.2.0 | Added optional RequestOptions parameter and ClientWithOptions support. |
Код HttpTransporter::send() HttpTransporter::send WP 7.1.4
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);
}