Documentation

NoPrivateNetworkHttpClient
in package
implements HttpClientInterface, LoggerAwareInterface, ResetInterface Uses HttpClientTrait

FinalYes

Decorator that blocks requests to private networks by default.

Tags
author

Hallison Boaventura hallisonboaventura@gmail.com

Table of Contents

Interfaces

HttpClientInterface
Provides flexible methods for requesting HTTP resources synchronously or asynchronously.
LoggerAwareInterface
Describes a logger-aware instance.
ResetInterface
Provides a way to reset an object to its initial state.

Constants

PRIVATE_SUBNETS  = ['127.0.0.0/8', '10.0.0.0/8', '192.168.0.0/16', '172.16.0.0/12', '169.254.0.0/16', '0.0.0.0/8', '240.0.0.0/4', '::1/128', 'fc00::/7', 'fe80::/10', '::ffff:0:0/96', '::/128']

Properties

$CHUNK_SIZE  : int
$client  : mixed
$subnets  : string|array<string|int, mixed>|null

Methods

__construct()  : mixed
request()  : ResponseInterface
Requests an HTTP resource.
reset()  : mixed
setLogger()  : void
Sets a logger instance on the object.
stream()  : ResponseStreamInterface
Yields responses chunk by chunk as they complete.
withOptions()  : static
Returns a new instance of the client with new default options.
dechunk()  : string
getProxy()  : array<string|int, mixed>|null
Loads proxy configuration from the same environment variables as curl when no proxy is explicitly set.
jsonEncode()  : string
mergeDefaultOptions()  : array<string|int, mixed>
mergeQueryString()  : string|null
Merges and encodes a query array with a query string.
normalizeBody()  : string|resource|Closure
normalizeHeaders()  : array<string|int, array<string|int, string>>
normalizePeerFingerprint()  : array<string|int, mixed>
parseUrl()  : array<string|int, mixed>
Parses a URL and fixes its encoding if needed.
prepareRequest()  : array<string|int, mixed>
Validates and normalizes method, URL and options, and merges them with defaults.
removeDotSegments()  : mixed
Removes dot-segments from a path.
resolveUrl()  : array<string|int, mixed>
Resolves a URL against a base URI.
shouldBuffer()  : bool

Constants

PRIVATE_SUBNETS

private mixed PRIVATE_SUBNETS = ['127.0.0.0/8', '10.0.0.0/8', '192.168.0.0/16', '172.16.0.0/12', '169.254.0.0/16', '0.0.0.0/8', '240.0.0.0/4', '::1/128', 'fc00::/7', 'fe80::/10', '::ffff:0:0/96', '::/128']

Properties

Methods

__construct()

public __construct(HttpClientInterface $client[, string|array<string|int, mixed>|null $subnets = null ]) : mixed
Parameters
$client : HttpClientInterface
$subnets : string|array<string|int, mixed>|null = null

String or array of subnets using CIDR notation that will be used by IpUtils. If null is passed, the standard private subnets will be used.

withOptions()

Returns a new instance of the client with new default options.

public withOptions(array<string|int, mixed> $options) : static
Parameters
$options : array<string|int, mixed>
Return values
static

dechunk()

private static dechunk(string $body) : string
Parameters
$body : string
Return values
string

getProxy()

Loads proxy configuration from the same environment variables as curl when no proxy is explicitly set.

private static getProxy(string|null $proxy, array<string|int, mixed> $url, string|null $noProxy) : array<string|int, mixed>|null
Parameters
$proxy : string|null
$url : array<string|int, mixed>
$noProxy : string|null
Return values
array<string|int, mixed>|null

jsonEncode()

private static jsonEncode(mixed $value[, int $flags = null ][, int $maxDepth = 512 ]) : string
Parameters
$value : mixed
$flags : int = null
$maxDepth : int = 512
Tags
throws
InvalidArgumentException

When the value cannot be json-encoded

Return values
string

mergeDefaultOptions()

private static mergeDefaultOptions(array<string|int, mixed> $options, array<string|int, mixed> $defaultOptions[, bool $allowExtraOptions = false ]) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>
$defaultOptions : array<string|int, mixed>
$allowExtraOptions : bool = false
Tags
throws
InvalidArgumentException

When an invalid option is found

Return values
array<string|int, mixed>

mergeQueryString()

Merges and encodes a query array with a query string.

private static mergeQueryString(string|null $queryString, array<string|int, mixed> $queryArray, bool $replace) : string|null
Parameters
$queryString : string|null
$queryArray : array<string|int, mixed>
$replace : bool
Tags
throws
InvalidArgumentException

When an invalid query-string value is passed

Return values
string|null

normalizeBody()

private static normalizeBody(array<string|int, mixed>|string|resource|Traversable|Closure $body) : string|resource|Closure
Parameters
$body : array<string|int, mixed>|string|resource|Traversable|Closure
Tags
throws
InvalidArgumentException

When an invalid body is passed

Return values
string|resource|Closure

normalizeHeaders()

private static normalizeHeaders(array<string|int, mixed> $headers) : array<string|int, array<string|int, string>>
Parameters
$headers : array<string|int, mixed>
Tags
throws
InvalidArgumentException

When an invalid header is found

Return values
array<string|int, array<string|int, string>>

normalizePeerFingerprint()

private static normalizePeerFingerprint(mixed $fingerprint) : array<string|int, mixed>
Parameters
$fingerprint : mixed
Tags
throws
InvalidArgumentException

When an invalid fingerprint is passed

Return values
array<string|int, mixed>

parseUrl()

Parses a URL and fixes its encoding if needed.

private static parseUrl(string $url[, array<string|int, mixed> $query = [] ][, array<string|int, mixed> $allowedSchemes = ['http' => 80, 'https' => 443] ]) : array<string|int, mixed>
Parameters
$url : string
$query : array<string|int, mixed> = []
$allowedSchemes : array<string|int, mixed> = ['http' => 80, 'https' => 443]
Tags
throws
InvalidArgumentException

When an invalid URL is passed

Return values
array<string|int, mixed>

prepareRequest()

Validates and normalizes method, URL and options, and merges them with defaults.

private static prepareRequest(string|null $method, string|null $url, array<string|int, mixed> $options[, array<string|int, mixed> $defaultOptions = [] ][, bool $allowExtraOptions = false ]) : array<string|int, mixed>
Parameters
$method : string|null
$url : string|null
$options : array<string|int, mixed>
$defaultOptions : array<string|int, mixed> = []
$allowExtraOptions : bool = false
Tags
throws
InvalidArgumentException

When a not-supported option is found

Return values
array<string|int, mixed>

resolveUrl()

Resolves a URL against a base URI.

private static resolveUrl(array<string|int, mixed> $url, array<string|int, mixed>|null $base[, array<string|int, mixed> $queryDefaults = [] ]) : array<string|int, mixed>
Parameters
$url : array<string|int, mixed>
$base : array<string|int, mixed>|null
$queryDefaults : array<string|int, mixed> = []
Tags
see
https://tools.ietf.org/html/rfc3986#section-5.2.2
throws
InvalidArgumentException

When an invalid URL is passed

Return values
array<string|int, mixed>

shouldBuffer()

private static shouldBuffer(array<string|int, mixed> $headers) : bool
Parameters
$headers : array<string|int, mixed>
Return values
bool

        
On this page

Search results