Request
class Request extends Message (View source)
The http\Client\Request class provides an HTTP message implementation tailored to represent a request message to be sent by the client.
See http\Client::enqueue().
Constants
TYPE_NONE |
No specific type of message. |
TYPE_REQUEST |
A request message. |
TYPE_RESPONSE |
A response message. |
Properties
protected int | $type | The message type. See http\Message::TYPE_* constants. |
from Message |
protected Body | $body | The message's body. |
from Message |
protected string | $requestMethod | The request method if the message is of type request. |
from Message |
protected string | $requestUrl | The request url if the message is of type request. |
from Message |
protected string | $responseStatus | The response status phrase if the message is of type response. |
from Message |
protected int | $responseCode | The response code if the message is of type response. |
from Message |
protected string | $httpVersion | A custom HTTP protocol version. |
from Message |
protected array | $headers | Any message headers. |
from Message |
protected Message | $parentMessage | Any parent message. |
from Message |
protected array | $options | Array of options for this request, which override client options. |
Methods
Create a new client request message to be enqueued and sent by http\Client.
Add an header, appending to already existing headers.
Add headers, optionally appending values, if header keys already exist.
Retrieve a single header, optionally hydrated into a http\Header extending class.
Check whether this message is a multipart message based on it's content type.
Prepend message(s) $message to this message, or the top most message of this message chain.
Set the HTTP protocol version of the message.
Set the complete message info, i.e. type and response resp. request information, at once.
Set the response status code.
Stream the message into stream $stream, starting from $offset, streaming $maxlen at most.
Retrieve the message serialized to a string.
Add specific SSL options.
Extract the currently set "Content-Type" header.
Get priorly set options.
Retrieve the currently set querystring.
Retrieve priorly set SSL options.
Set the MIME content type of the request message.
Set client options.
Specifically set SSL options.
Details
__construct(string $meth = null, string $url = null, array $headers = null, Body $body = null)
Create a new client request message to be enqueued and sent by http\Client.
string
__toString()
Retrieve the message serialized to a string.
Alias of http\Message::toString().
Message
addBody(Body $body)
Append the data of $body to the message's body.
See http\Message::setBody() and http\Message\Body::append().
Message
addHeader(string $name, mixed $value)
Add an header, appending to already existing headers.
See http\Message::addHeaders() and http\Message::setHeader().
Message
addHeaders(array $headers, bool $append = false)
Add headers, optionally appending values, if header keys already exist.
See http\Message::addHeader() and http\Message::setHeaders().
int
count()
Implements Countable.
mixed
current()
Implements iterator.
See http\Message::valid() and http\Message::rewind().
Message
detach()
Detach a clone of this message from any message chain.
Body
getBody()
Retrieve the message's body.
See http\Message::setBody().
mixed|Header
getHeader(string $header, string $into_class = null)
Retrieve a single header, optionally hydrated into a http\Header extending class.
array
getHeaders()
Retrieve all message headers.
See http\Message::setHeaders() and http\Message::getHeader().
string
getHttpVersion()
Retrieve the HTTP protocol version of the message.
See http\Message::setHttpVersion().
string|null
getInfo()
Retrieve the first line of a request or response message.
See http\Message::setInfo and also:
- http\Message::getType()
- http\Message::getHttpVersion()
- http\Message::getResponseCode()
- http\Message::getResponseStatus()
- http\Message::getRequestMethod()
- http\Message::getRequestUrl()
Message
getParentMessage()
Retrieve any parent message.
See http\Message::reverse().
string|false
getRequestMethod()
Retrieve the request method of the message.
See http\Message::setRequestMethod() and http\Message::getRequestUrl().
string|false
getRequestUrl()
Retrieve the request URL of the message.
See http\Message::setRequestUrl().
int|false
getResponseCode()
Retrieve the response code of the message.
See http\Message::setResponseCode() and http\Message::getResponseStatus().
string|false
getResponseStatus()
Retrieve the response status of the message.
See http\Message::setResponseStatus() and http\Message::getResponseCode().
int
getType()
Retrieve the type of the message.
See http\Message::setType() and http\Message::getInfo().
bool
isMultipart(string $boundary = null)
Check whether this message is a multipart message based on it's content type.
If the message is a multipart message and a reference $boundary is given, the boundary string of the multipart message will be stored in $boundary.
See http\Message::splitMultipartBody().
mixed
key()
Implements Iterator.
See http\Message::current() and http\Message::rewind().
void
next()
Implements Iterator.
See http\Message::valid() and http\Message::rewind().
Message
prepend(Message $message, bool $top = true)
Prepend message(s) $message to this message, or the top most message of this message chain.
NOTE: The message chains must not overlap.
Message
reverse()
Reverse the message chain and return the former top-most message.
NOTE: Message chains are ordered in reverse-parsed order by default, i.e. the last parsed message is the message you'll receive from any call parsing HTTP messages.
This call re-orders the messages of the chain and returns the message that was parsed first with any later parsed messages re-parentized.
void
rewind()
Implements Iterator.
string|null
serialize()
Implements Serializable.
Message
setBody(Body $body)
Set the message's body.
See http\Message::getBody() and http\Message::addBody().
Message
setHeader(string $header, mixed $value = null)
Set a single header.
See http\Message::getHeader() and http\Message::addHeader().
NOTE: Prior to v2.5.6/v3.1.0 headers with the same name were merged into a single header with values concatenated by comma.
Message
setHeaders(array $headers = null)
Set the message headers.
See http\Message::getHeaders() and http\Message::addHeaders().
NOTE: Prior to v2.5.6/v3.1.0 headers with the same name were merged into a single header with values concatenated by comma.
Message
setHttpVersion(string $http_version)
Set the HTTP protocol version of the message.
See http\Message::getHttpVersion().
Message
setInfo(string $http_info)
Set the complete message info, i.e. type and response resp. request information, at once.
See http\Message::getInfo().
Message
setRequestMethod(string $method)
Set the request method of the message.
See http\Message::getRequestMethod() and http\Message::setRequestUrl().
Message
setRequestUrl(string $url)
Set the request URL of the message.
See http\Message::getRequestUrl() and http\Message::setRequestMethod().
Message
setResponseCode(int $response_code, bool $strict = true)
Set the response status code.
See http\Message::getResponseCode() and http\Message::setResponseStatus().
NOTE: This method also resets the response status phrase to the default for that code.
Message
setResponseStatus(string $response_status)
Set the response status phrase.
See http\Message::getResponseStatus() and http\Message::setResponseCode().
Message
setType(int $type)
Set the message type and reset the message info.
See http\Message::getType() and http\Message::setInfo().
Message
splitMultipartBody()
Splits the body of a multipart message.
See http\Message::isMultipart() and http\Message\Body::addPart().
Message
toCallback(callable $callback)
Stream the message through a callback.
Message
toStream(resource $stream)
Stream the message into stream $stream, starting from $offset, streaming $maxlen at most.
string
toString(bool $include_parent = false)
Retrieve the message serialized to a string.
void
unserialize(string $data)
Implements Serializable.
bool
valid()
Implements Iterator.
See http\Message::current() and http\Message::rewind().
Request
addQuery(mixed $query_data)
Add querystring data.
See http\Client\Request::setQuery() and http\Message::setRequestUrl().
Request
addSslOptions(array $ssl_options = null)
Add specific SSL options.
See http\Client\Request::setSslOptions(), http\Client\Request::setOptions() and http\Client\Curl\$ssl options.
string|null
getContentType()
Extract the currently set "Content-Type" header.
See http\Client\Request::setContentType().
array
getOptions()
Get priorly set options.
See http\Client\Request::setOptions().
string|null
getQuery()
Retrieve the currently set querystring.
array
getSslOptions()
Retrieve priorly set SSL options.
See http\Client\Request::getOptions() and http\Client\Request::setSslOptions().
Request
setContentType(string $content_type)
Set the MIME content type of the request message.
Request
setOptions(array $options = null)
Set client options.
See http\Client::setOptions() and http\Client\Curl.
Request specific options override general options which were set in the client.
NOTE: Only options specified prior enqueueing a request are applied to the request.
Request
setQuery(mixed $query_data)
(Re)set the querystring.
See http\Client\Request::addQuery() and http\Message::setRequestUrl().
Request
setSslOptions(array $ssl_options = null)
Specifically set SSL options.
See http\Client\Request::setOptions() and http\Client\Curl\$ssl options.