Response
class Response extends Message (View source)
The http\Env\Response class' instances represent the server's current HTTP response.
See http\Message for inherited members.
Constants
TYPE_NONE |
No specific type of message. |
TYPE_REQUEST |
A request message. |
TYPE_RESPONSE |
A response message. |
CONTENT_ENCODING_NONE |
Do not use content encoding. |
CONTENT_ENCODING_GZIP |
Support "Accept-Encoding" requests with gzip and deflate encoding. |
CACHE_NO |
No caching info available. |
CACHE_HIT |
The cache was hit. |
CACHE_MISS |
The cache was missed. |
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 Request | $request | A request instance which overrides the environments default request. |
|
protected string | $contentType | The response's MIME content type. |
|
protected string | $contentDisposition | The response's MIME content disposition. |
|
protected int | $contentEncoding | See http\Env\Response::CONTENTENCODING* constants. |
|
protected string | $cacheControl | How the client should treat this response in regards to caching. |
|
protected string | $etag | A custom ETag. |
|
protected int | $lastModified | A "Last-Modified" time stamp. |
|
protected int | $throttleDelay | Any throttling delay. |
|
protected int | $throttleChunk | The chunk to send every $throttleDelay seconds. |
|
protected array | $cookies | The response's cookies. |
Methods
Create a new env response message instance.
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.
Output buffer handler.
Manually test the header $header_name of the environment's request for a cache hit.
Manually test the header $header_name of the environment's request for a cache hit.
Send the response through the SAPI or $stream.
Make suggestions to the client how it should cache the response.
Set the response's content disposition parameters.
Enable support for "Accept-Encoding" requests with deflate or gzip.
Set the MIME content type of the response.
Override the environment's request.
Set a custom last modified time stamp.
Enable throttling.
Details
__construct()
Create a new env response message instance.
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().
bool
__invoke(string $data, int $ob_flags = 0)
Output buffer handler.
Appends output data to the body.
int
isCachedByEtag(string $header_name = "If-None-Match")
Manually test the header $header_name of the environment's request for a cache hit.
http\Env\Response::send() checks that itself, though.
int
isCachedByLastModified(string $header_name = "If-Modified-Since")
Manually test the header $header_name of the environment's request for a cache hit.
http\Env\Response::send() checks that itself, though.
bool
send(resource $stream = null)
Send the response through the SAPI or $stream.
Flushes all output buffers.
Response
setCacheControl(string $cache_control)
Make suggestions to the client how it should cache the response.
Response
setContentDisposition(array $disposition_params)
Set the response's content disposition parameters.
Response
setContentEncoding(int $content_encoding)
Enable support for "Accept-Encoding" requests with deflate or gzip.
The response will be compressed if the client indicates support and wishes that.
Response
setContentType(string $content_type)
Set the MIME content type of the response.
Response
setCookie(mixed $cookie)
Add cookies to the response to send.
Response
setEnvRequest(Message $env_request)
Override the environment's request.
Response
setEtag(string $etag)
Set a custom ETag.
NOTE: This will be used for caching and pre-condition checks.
Response
setLastModified(int $last_modified)
Set a custom last modified time stamp.
NOTE: This will be used for caching and pre-condition checks.
Response
setThrottleRate(int $chunk_size, float $delay = 1)
Enable throttling.
Send $chunk_size bytes every $delay seconds.
NOTE: If you need throttling by regular means, check for other options in your stack, because this method blocks the executing process/thread until the response has completely been sent.