Request::__construct( string $method, string|WordPressAiClientDependenciesPsrHttpMessageUriInterface $uri, array $headers = [], string|resource|WordPressAiClientDependenciesPsrHttpMessageStreamInterface|null $body = null, string $version = '1.1' )

In this article

Parameters

$methodstringrequired
HTTP method
$uristring|WordPressAiClientDependenciesPsrHttpMessageUriInterfacerequired
URI
$headersarrayoptional
Request headers

Default:[]

$bodystring|resource|WordPressAiClientDependenciesPsrHttpMessageStreamInterface|nulloptional
Request body

Default:null

$versionstringoptional
Protocol version

Default:'1.1'

Source

public function __construct(string $method, $uri, array $headers = [], $body = null, string $version = '1.1')
{
    if (!$uri instanceof UriInterface) {
        $uri = new Uri($uri);
    }
    $this->method = $method;
    $this->uri = $uri;
    $this->setHeaders($headers);
    $this->protocol = $version;
    if (!$this->hasHeader('Host')) {
        $this->updateHostFromUri();
    }
    // If we got no body, defer initialization of the stream until Request::getBody()
    if ('' !== $body && null !== $body) {
        $this->stream = Stream::create($body);
    }
}

User Contributed Notes

You must log in before being able to contribute a note or feedback.