Request
Request
HTTP Request class.
This class is used to create and manage HTTP requests. It is used by the Client class to create and send requests to remote servers. The Request class is used to create the request and the Client class is used to send the request and receive the response.
The Request class is used to create the request and the Client class is used to send the request and receive the response.
Properties
method
public string $method = 'GET'context
public mixed $contexturl
public URL $urlheaders
private $headers = array (
'User-Agent' => 'hazaar-php/',
0 => '.',
1 => 'HAZAAR_VERSION',
2 => '.',
3 => ' (PHP)',
'Content-Type' => 'text/html',
'Connection' => 'close',
)fsockHost
private string $fsockHostbody
private mixed $bodymultipart
private bool $multipartdontEncodeURL
private bool $dontEncodeURLjsonEncodeFlags
private int $jsonEncodeFlagsjsonEncodeDepth
private int $jsonEncodeDepth = 512data
private array $dataMethods
__construct
HTTP request constructor.
public __construct(URL $url, string $method = 'GET', ?string $contentType, mixed $customContext): voidParameters
| Parameter | Type | Description |
|---|---|---|
$url | URL | The url of the resource that will be requested |
$method | string | The request method to use. Typically GET, POST, etc |
$contentType | string | optionally set the content type header |
$customContext | mixed | Optionally use a custom context. Allows to define private SSL certificates. |
url
Set the url of the resource that is being requested.
public url(URL $url): URLParameters
| Parameter | Type | Description |
|---|---|---|
$url | URL |
appendURL
public appendURL(string $path): voidParameters
| Parameter | Type | Description |
|---|---|---|
$path | string |
setContentType
Sets the Content-Type header for the request.
public setContentType(string $contentType): voidParameters
| Parameter | Type | Description |
|---|---|---|
$contentType | string |
getContentType
Returns the current Content-Type header for the request.
public getContentType(): stringenableMultipart
Enable multipart mime request body optionally using the specified boundary and content type.
public enableMultipart(?string $contentType, ?string $boundary): boolParameters
| Parameter | Type | Description |
|---|---|---|
$contentType | string | Optional request content type to use. Defaults to multipart/form-data. |
$boundary | string | Optional boundary identifier. Defaults to HazaarMultipartBoundary_{uniqid} |
isMultipart
Returns a boolean indicating if the request is a multipart request.
public isMultipart(): boolgetMultipartBoundary
Return the current multipart boundary name.
public getMultipartBoundary(): stringaddMultipart
Add a multipart chunk to the request.
public addMultipart(mixed $data, ?string $contentType, ?array $headers): voidParameters
| Parameter | Type | Description |
|---|---|---|
$data | mixed | the data to add to the request |
$contentType | string | the content type of the added data |
$headers | array |
getHost
Returns the name of the host that will be sent this request.
public getHost(): stringsetBody
Set the request body.
public setBody(mixed $body, ?string $contentType): voidIf multipart is enabled, then the body will be added as a new chunk.
Parameters
| Parameter | Type | Description |
|---|---|---|
$body | mixed | |
$contentType | string |
getBody
Return the body of the request.
public getBody(): voidIf multipart is enabled, this will return an array containing request body and content type.
getHeaders
Returns all the headers currently set on the request.
public getHeaders(): voidgetHeader
Returns the value of the header specified by $key.
public getHeader(string $key): stringParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | The name of the header to return |
setHeader
Sets the value of a header.
public setHeader(string $key, string $value, bool $allowMultiple): voidParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the name of the header to set |
$value | string | the value to set on the header |
$allowMultiple | bool | Whether multiple instances of the header are allowed. Defaults to false, meaning if the header exists, it will be updated. Multiple headers are rare but the main one is 'Cookie'. |
toString
Output the request as a string.
public toString(?string $encryptionKey, ?string $encryptionCipher): stringThis is the method that renders the request as a HTTP/1.1 compliant request.
Parameters
| Parameter | Type | Description |
|---|---|---|
$encryptionKey | string | optionally encrypt the request using this encryption key |
$encryptionCipher | string | optionally specifiy the cipher used to encrypt the request |
authorise
Add Basic HTTP authentication.
public authorise(string $username, string $password): voidBasic authentication should ONLY be used over HTTPS.
Other methods are not yet supported, however Bearer is implemented using Request::authorization() method.
Parameters
| Parameter | Type | Description |
|---|---|---|
$username | string | The username to send |
$password | string | The password to send |
authorization
Alias for 'authorisation' for the bad 'merican spells.
public authorization(Adapter $user, string $type = 'Bearer'): boolParameters
| Parameter | Type | Description |
|---|---|---|
$user | Adapter | |
$type | string |
authorisation
Use an auth adapter to set an Oauth token on the request.
public authorisation(Adapter $user, ?string $type): boolParameters
| Parameter | Type | Description |
|---|---|---|
$user | Adapter | |
$type | string |
setLocalCertificate
Set a local PEM encoded certificate to use for SSL communication.
public setLocalCertificate(string $localCert, ?string $passphrase, ?string $localPk): boolParameters
| Parameter | Type | Description |
|---|---|---|
$localCert | string | |
$passphrase | string | |
$localPk | string |
setContextOption
Wrapper function to the internal PHP function stream_context_set_option() function.
public setContextOption(array $options): boolSee http://php.net/manual/en/context.ssl.php documentation for all the available wrappers and options.
Parameters
| Parameter | Type | Description |
|---|---|---|
$options | array | Must be an associative array in the format $arr['wrapper']['option'] = $value; |
allowSelfSigned
When using SSL communications, this allows the use of self-signed certificates.
public allowSelfSigned(bool $value = true): boolParameters
| Parameter | Type | Description |
|---|---|---|
$value | bool |
verifyPeer
When using SSL communications, this sets whether peer certificate verification is used.
public verifyPeer(bool $value = true): boolParameters
| Parameter | Type | Description |
|---|---|---|
$value | bool |
verifyPeerName
When using SSL communications, this sets whether peer name verification is used.
public verifyPeerName(bool $value = true): boolParameters
| Parameter | Type | Description |
|---|---|---|
$value | bool |
setURLEncode
Enable/Disable URL encoding.
public setURLEncode(bool $value = true): voidurl encoding is enabled by default. Internally this calls PHPs rawurlencode() function to encode URLs into HTTP safe urls. However there may occasionally be special circumstances where the encoding may need to be disabled. Usually this is becuase the encoding is already being done by the calling function/class.
A prime example of this is Hazaar's SharePoint filesystem backend driver. SharePoint is very finicky about the format of the urls and wants some characters left alone (ie: brackets and quotes) as they make up the function/path reference being accessed. These functions/references will then have their contents only encoded and this is handled by the driver itself so encoding again in the Request class will screw things up.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | bool | TRUE enables encoding (the default). FALSE will disable encoding. |
setJSONEncodeFlags
Set JSON encoding flags/depth used when request is encoded to JSON.
public setJSONEncodeFlags(int $flags, int $depth = 512): voidRequests will automatically encode any data parameters to JSON encoded strings when generating the reqeust as a string. If there are any JSON encoding flags required, this function will apply those flags to all JSON encoding methods used when rendering the request. This includes requests sent with a mime content type of application/json as well as multipart encoded requests.
Parameters
| Parameter | Type | Description |
|---|---|---|
$flags | int | |
$depth | int |
toJSON
public toJSON(int $flags, int $depth = 512): stringParameters
| Parameter | Type | Description |
|---|---|---|
$flags | int | |
$depth | int |
offsetExists
public offsetExists(mixed $offset): boolParameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
offsetGet
public offsetGet(mixed $offset): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
offsetSet
public offsetSet(mixed $offset, mixed $value): voidParameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | |
$value | mixed |
offsetUnset
public offsetUnset(mixed $offset): voidParameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
count
public count(): inttoArray
public toArray(): voidpopulate
public populate(array $data): voidParameters
| Parameter | Type | Description |
|---|---|---|
$data | array |
Generated by Hazaar API Doc Generator on Wed, 07 Jan 2026 11:30:00 +0000