Response
Response
class Response implements \ArrayAccessImplements: ArrayAccess
Properties
status
public int $statusType: int
name
The status message associated with the response code (e.g., "OK", "Not Found").
public string $nameType: string
version
The HTTP version of the response (e.g., "HTTP/1.1").
public string $versionType: string
body
The actual body of the response.
public array|string $bodyType: array|string
contentLength
The length of the response body in bytes.
public int $contentLengthType: int
bytesRemaining
The number of bytes remaining to be read from the response body.
public int $bytesRemaining = -1Type: int
headers
public array $headersType: array
buffer
public string $bufferType: string
headersParsed
Indicates whether the response headers have been parsed.
private bool $headersParsedType: bool
chunked
Indicates whether the response uses chunked transfer encoding.
private bool $chunkedType: bool
chunkOffset
The offset for the current chunk when parsing chunked data.
private int $chunkOffsetType: int
Methods
__construct
public __construct(?int $status, array $headers, string $version = 'HTTP/1.1'): voidParameters
| Parameter | Type | Description |
|---|---|---|
$status | int | |
$headers | array | |
$version | string |
offsetGet
ArrayAccess method to allow access to headers as properties.
public offsetGet(mixed $offset): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
offsetSet
ArrayAccess method to allow access to headers as properties.
public offsetSet(mixed $offset, mixed $value): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | |
$value | mixed | The value to set |
offsetExists
ArrayAccess method to allow access to headers as properties.
public offsetExists(mixed $offset): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
offsetUnset
ArrayAccess method to allow access to headers as properties.
public offsetUnset(mixed $offset): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
setStatus
Sets the HTTP status code and updates the status message.
public setStatus(int $status): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$status | int | the HTTP status code to set |
write
Appends data to the response body and updates the content length.
public write(string $string): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$string | string | the data to append to the response body |
read
Reads and parses data from the response buffer.
public read(string $buffer): boolReturns: bool
Handles header parsing, chunked transfer decoding, and body accumulation. Returns true when the response is fully read.
Parameters
| Parameter | Type | Description |
|---|---|---|
$buffer | string | the buffer data to read and parse |
hasHeader
Checks if a header exists in the response.
public hasHeader(string $key): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the header key to check |
getHeader
Get a header from the response.
public getHeader(string $header): array|string|nullReturns: array|string|null
Parameters
| Parameter | Type | Description |
|---|---|---|
$header | string | The header key to get |
setHeader
Sets or removes a header in the response.
public setHeader(string $header, ?string $content): voidReturns: void
If content is null, the header is removed. Otherwise, the header is set to the provided value.
Parameters
| Parameter | Type | Description |
|---|---|---|
$header | string | the header key to set or remove |
$content | string | the value to set, or null to remove the header |
size
Returns the size of the response body in bytes.
public size(): intReturns: int
toString
Converts the response object to its string representation as a raw HTTP response.
public toString(): stringReturns: string
Includes the status line, headers, and body, formatted according to HTTP/1.1 standards.
getStatusMessage
public getStatusMessage(?int $code): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$code | int |
getContentType
Get the content type of the response.
public getContentType(array $args): stringReturns: string
This method will return the content type of the response and optionally return any arguments that were
Parameters
| Parameter | Type | Description |
|---|---|---|
$args | array | The arguments of the content type header will be returned in this array |
body
public body(bool $raw): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$raw | bool |
getText
Helper function to get the status text for an HTTP response code.
public getText(int $code): voidParameters
| Parameter | Type | Description |
|---|---|---|
$code | int | the response code |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:18 +0000