Client
Client
HTTP Client for making requests and handling responses.
class ClientThis class provides methods for sending HTTP requests, managing cookies, headers, authentication, and handling redirects. It supports GET, POST, DELETE, TRACE, OPTIONS, and HEAD methods.
Properties
bufferSize
Buffer size for reading response data.
private int $bufferSize = 4096Type: int
connectionTimeout
Connection timeout in seconds.
private int $connectionTimeout = 5Type: int
headers
Request headers.
private array $headersType: array
cookies
Cookies for the request.
private array $cookiesType: array
localCert
public string $localCertType: string
certPassphrase
public string $certPassphraseType: string
autoRedirect
Whether to automatically follow redirects.
private bool $autoRedirect = trueType: bool
redirectMethods
HTTP methods allowed for redirects.
private array $redirectMethods = array (
0 => 'GET',
1 => 'OPTIONS',
2 => 'PROPFIND',
)Type: array
username
public string $usernameType: string
password
public string $passwordType: string
auth
public Adapter $authType: Hazaar\Auth\Adapter
Methods
__construct
Constructs a new HTTP Client instance.
public __construct(?string $localCert, ?string $passphrase): voidParameters
| Parameter | Type | Description |
|---|---|---|
$localCert | string | path to local certificate file for SSL |
$passphrase | string | passphrase for the certificate file |
auth
Sets basic authentication credentials for HTTP requests.
public auth(string $username, string $password): voidReturns: void
Stores the provided username and password for use in subsequent requests requiring authentication.
Parameters
| Parameter | Type | Description |
|---|---|---|
$username | string | the username for authentication |
$password | string | the password for authentication |
authorisation
Sets an authentication adapter for advanced authentication mechanisms.
public authorisation(Adapter $auth): voidReturns: void
Stores the provided authentication adapter instance for use in requests requiring custom authentication.
Parameters
| Parameter | Type | Description |
|---|---|---|
$auth | Hazaar\Auth\Adapter | the authentication adapter instance |
setHeader
Sets a custom header for HTTP requests.
public setHeader(string $header, string $value): voidReturns: void
Adds or updates the specified header and value for use in subsequent requests.
Parameters
| Parameter | Type | Description |
|---|---|---|
$header | string | the header name |
$value | string | the header value |
options
Sends an HTTP OPTIONS request to the specified URL.
public options(string $url): false|ResponseReturns: false|Hazaar\HTTP\Response
Parameters
| Parameter | Type | Description |
|---|---|---|
$url | string | the URL to send the OPTIONS request to |
get
Sends an HTTP GET request to the specified URL, with support for redirects and partial content.
public get(string|URL $url, int $redirectLimit = 10, int $offset = -1, ?int $maxlen): false|ResponseReturns: false|Hazaar\HTTP\Response
Parameters
| Parameter | Type | Description |
|---|---|---|
$url | string | Hazaar\HTTP\URL |
$redirectLimit | int | maximum number of redirects to follow |
$offset | int | byte offset for partial content (default: -1) |
$maxlen | int | maximum length of content to retrieve (optional) |
head
Sends an HTTP HEAD request to the specified URL, with support for redirects.
public head(string|URL $url, int $redirectLimit = 10): false|ResponseReturns: false|Hazaar\HTTP\Response
Parameters
| Parameter | Type | Description |
|---|---|---|
$url | string | Hazaar\HTTP\URL |
$redirectLimit | int | maximum number of redirects to follow |
post
Sends an HTTP POST request to the specified URL, with optional data and content type.
public post(string|URL $url, null|array|Element|string|\stdClass $data, ?string $dataType, int $redirectLimit): false|ResponseReturns: false|Hazaar\HTTP\Response
Parameters
| Parameter | Type | Description |
|---|---|---|
$url | string | Hazaar\HTTP\URL |
$data | null | array |
$dataType | string | the content type of the POST data (optional, default: text/html) |
$redirectLimit | int | maximum number of redirects to follow (default: 0) |
delete
Sends an HTTP DELETE request to the specified URL.
public delete(string|URL $url): false|ResponseReturns: false|Hazaar\HTTP\Response
Parameters
| Parameter | Type | Description |
|---|---|---|
$url | string | Hazaar\HTTP\URL |
trace
Sends an HTTP TRACE request to the specified URL.
public trace(string|URL $url): false|ResponseReturns: false|Hazaar\HTTP\Response
Parameters
| Parameter | Type | Description |
|---|---|---|
$url | string | Hazaar\HTTP\URL |
send
Send a request to the desination host.
public send(Request $request, int $redirectLimit = 10): ?ResponseReturns: Hazaar\HTTP\Response
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | Hazaar\HTTP\Request | The request to send |
$redirectLimit | int | The number of allowed redirects. To disable automated redirects on this request, set to FALSE. |
getCookies
public getCookies(): array|stringReturns: array|string
getCookie
public getCookie(string $name): array|string|nullReturns: array|string|null
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string |
hasCookie
Checks if a cookie with the specified name exists.
public hasCookie(string $name): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the cookie to check |
deleteCookie
Deletes a cookie with the specified name.
public deleteCookie(string $name): voidReturns: void
Removes the cookie from the internal cookie storage if it exists.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the cookie to delete |
setCookie
public setCookie(array|string $cookie): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$cookie | array | string |
cacheCookie
Caches cookies using the provided cache adapter.
public cacheCookie(CacheAdapter $cache, bool $cacheAll): boolReturns: bool
Stores all or only valid cookies in the cache, depending on the cacheAll flag.
Parameters
| Parameter | Type | Description |
|---|---|---|
$cache | Hazaar\Cache\Adapter | the cache adapter to use for storing cookies |
$cacheAll | bool | whether to cache all cookies or only valid ones |
uncacheCookie
Restores cookies from the provided cache adapter.
public uncacheCookie(CacheAdapter $cache): boolReturns: bool
Loads cookies from the cache and sets them in the client. Returns true if successful, false otherwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
$cache | Hazaar\Cache\Adapter | the cache adapter to retrieve cookies from |
deleteCookies
Deletes all cookies from the client.
public deleteCookies(): voidReturns: void
Clears the internal cookie storage.
disableRedirect
Disables automatic HTTP redirects for requests.
public disableRedirect(): voidReturns: void
Sets the autoRedirect flag to false, preventing the client from following redirects.
applyCookies
Applies stored cookies to the given HTTP request.
private applyCookies(Request $request): RequestReturns: Hazaar\HTTP\Request
Filters cookies by domain, path, expiration, and security, then sets the Cookie header on the request.
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | Hazaar\HTTP\Request | the request to apply cookies to |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:18 +0000