HttpClientService
in package
HTTP Client Service — safe outbound HTTP with SSRF protection.
All outbound HTTP requests from the framework SHOULD use this service to benefit from private IP blocking, DNS rebinding protection, SSL verification, response size limits, and timeout enforcement.
Table of Contents
Methods
- get() : array{status: int, body: string, headers: array, error: ?string}
- Perform a GET request.
- isBlockedHost() : bool
- Check if a hostname is in the blocked list.
- isPrivateIp() : bool
- Check if an IP address is in a private/reserved range.
- post() : array{status: int, body: string, headers: array, error: ?string}
- Perform a POST request.
- request() : array{status: int, body: string, headers: array, error: ?string}
- Perform an HTTP request with SSRF protection.
Methods
get()
Perform a GET request.
public
static get(string $url[, array<string|int, mixed> $headers = [] ][, array<string|int, mixed> $options = [] ]) : array{status: int, body: string, headers: array, error: ?string}
Parameters
- $url : string
-
The URL to fetch
- $headers : array<string|int, mixed> = []
-
Additional headers
- $options : array<string|int, mixed> = []
-
Override options (timeout, maxSize, verifySsl)
Return values
array{status: int, body: string, headers: array, error: ?string}isBlockedHost()
Check if a hostname is in the blocked list.
public
static isBlockedHost(string $host) : bool
Parameters
- $host : string
Return values
boolisPrivateIp()
Check if an IP address is in a private/reserved range.
public
static isPrivateIp(string $ip) : bool
Blocks: RFC 1918, link-local, loopback, multicast, reserved
Parameters
- $ip : string
-
The IP address to check
Return values
bool —True if the IP is private/reserved
post()
Perform a POST request.
public
static post(string $url[, string|null $body = null ][, array<string|int, mixed> $headers = [] ][, array<string|int, mixed> $options = [] ]) : array{status: int, body: string, headers: array, error: ?string}
Parameters
- $url : string
-
The URL to post to
- $body : string|null = null
-
Request body
- $headers : array<string|int, mixed> = []
-
Additional headers
- $options : array<string|int, mixed> = []
-
Override options
Return values
array{status: int, body: string, headers: array, error: ?string}request()
Perform an HTTP request with SSRF protection.
public
static request(string $method, string $url[, string|null $body = null ][, array<string|int, mixed> $headers = [] ][, array<string|int, mixed> $options = [] ]) : array{status: int, body: string, headers: array, error: ?string}
Parameters
- $method : string
-
HTTP method
- $url : string
-
Target URL
- $body : string|null = null
-
Request body (for POST/PUT/PATCH)
- $headers : array<string|int, mixed> = []
-
Additional headers
- $options : array<string|int, mixed> = []
-
Override options