WP_AI_Client_HTTP_Client::prepare_bodyprivateWP 7.0.0

Prepares request body for WordPress HTTP API.

Method of the class: WP_AI_Client_HTTP_Client{}

No Hooks.

Returns

String|null. The request body.

Usage

// private - for code of main (parent) class only
$result = $this->prepare_body( $request ): ?string;
$request(RequestInterface) (required)
The PSR-7 request.

Changelog

Since 7.0.0 Introduced.

WP_AI_Client_HTTP_Client::prepare_body() code WP 7.0

private function prepare_body( RequestInterface $request ): ?string {
	$body = $request->getBody();

	if ( $body->getSize() === 0 ) {
		return null;
	}

	if ( $body->isSeekable() ) {
		$body->rewind();
	}

	return (string) $body;
}