class PendingRequest implements Transient

Traits

Constants

DATA_OPTION

PRIOR_SENDS_OPTION

DESTINATION_POLICY_OPTION

TRACE_OPTION

TRACE_PROPAGATION_OPTION

DEFAULT_DESTINATION_RESOLUTION_TIMEOUT

protected PREPARED_BODY_OPTION

protected STUB_SINK_CHUNK_SIZE

The largest faked body write to a sink, matching cURL's default maximum write size.

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected ClientInterface|null $client

The Guzzle client instance.

protected callable $handler

The Guzzle HTTP handler.

protected string $baseUrl

The base URL for the request.

protected array $urlParameters

The parameters that can be substituted into the URL.

protected string $bodyFormat

The request body format.

protected null|resource|StreamInterface|string $pendingBody

The raw body for the request.

protected array $pendingFiles

The pending files for the request.

protected StreamInterface> $multipartStreams

The streams wrapping attached multipart resources, keyed by resource ID.

protected CookieJar $cookies

The request cookies.

protected TransferStats|null $transferStats

The transfer stats for the request.

protected int $sendCount

The number of physical requests started during the current logical send.

protected array $options

The request options.

protected array $baseOptions

The factory-level options applied below connection and request options.

protected Closure|null $throwCallback

A callback to run when throwing if a server or client error occurs.

protected Closure|null $throwIfCallback

A callback to check if an exception should be thrown when a server or client error occurs.

protected array<int, float|int>|int $tries

The number of times to try the request.

protected Throwable): int|int $retryDelay

The number of milliseconds to wait between retries.

protected bool $retryThrow

Whether to throw an exception when all retries fail.

protected null|callable(null|Throwable, static, null|string): bool $retryWhenCallback

The callback that will determine if the request should be retried.

protected Collection $beforeSendingCallbacks

The callbacks that should execute before the request is sent.

protected Response, null|Request): mixed> $afterResponseCallbacks

The callbacks that should execute after the response is built.

protected Collection|null $stubCallbacks

The stub callables that will handle requests.

protected bool $preventStrayRequests

Indicates that an exception should be thrown if any request is not faked.

protected array $allowedStrayRequestUrls

The URL patterns that are allowed as stray requests.

protected Collection $middleware

The middleware callables added by users that will handle requests.

protected TAsync $async

Whether the requests should be asynchronous.

protected array $attributes

The attributes to track with the request.

protected PromiseInterface|null $promise

The pending request promise.

protected Request|null $request

The sent request object, if a request has been made.

protected string|null $connection

The current connection name for the pending request.

protected array|null $connectionConfig

The current connection configuration for the pending request.

protected array $mergeableOptions

The Guzzle request options whose entries accumulate across option layers.

protected false|int|null $truncateExceptionsAt

The length at which request exceptions will be truncated.

Methods

mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

__construct(Factory|null $factory = null, array $middleware = [], array $options = [])

Create a new HTTP Client instance.

baseUrl(string $url)

Set the base URL for the pending request.

withBody(mixed $content, string|null $contentType = 'application/json')

Attach a raw body to the request.

asJson()

Indicate the request contains JSON.

asForm()

Indicate the request contains form parameters.

attach(array|string $name, resource|string $contents = '', string|null $filename = null, array $headers = [])

Attach a file to the request.

asMultipart()

Indicate the request is a multi-part form request.

bodyFormat(string $format)

Specify the body format of the request.

withQueryParameters(array $parameters)

Set the given query parameters in the request URI.

contentType(string $contentType)

Specify the request's content type.

acceptJson()

Indicate that JSON should be returned by the server.

accept(string $contentType)

Indicate the type of content that should be returned by the server.

withHeaders(array $headers)

Add the given headers to the request.

withHeader(string $name, mixed $value)

Add the given header to the request.

replaceHeaders(array $headers)

Replace the given headers on the request.

withBasicAuth(string $username, string $password)

Specify the basic authentication username and password for the request.

withDigestAuth(string $username, string $password)

Specify the digest authentication username and password for the request.

withToken(string $token, string $type = 'Bearer')

Specify an authorization token for the request.

withUserAgent(bool|string $userAgent)

Specify the user agent for the request.

withUrlParameters(array $parameters = [])

Specify the URL parameters that can be substituted into the request URL.

withCookie(SetCookie $cookie)

Specify a cookie and its attributes for the request.

withCookies(array $cookies, string $domain)

Specify the cookies that should be included with the request.

maxRedirects(int $max)

Specify the maximum number of redirects to allow.

withoutRedirecting()

Indicate that redirects should not be followed.

withoutVerifying()

Indicate that TLS certificates should not be verified.

withDestinationPolicy(DestinationPolicy $policy)

Restrict the request's destinations to those the given policy allows.

resolveDestination(DestinationPolicy $policy, string $url)

Resolve and pin a destination within this request's timeout limits.

sink(resource|StreamInterface|string $to)

Specify the path where the body of the response should be stored.

timeout(float|int $seconds)

Specify the timeout (in seconds) for the request.

connectTimeout(float|int $seconds)

Specify the connect timeout (in seconds) for the request.

retry(array|int $times, Closure|int $sleepMilliseconds = 0, callable|null $when = null, bool $throw = true)

Specify the number of times the request should be attempted.

withOptions(array $options)

Replace the specified options on the request.

withMiddleware(callable $middleware)

Add new middleware the client handler stack.

prependMiddleware(callable $middleware)

Prepend new middleware to the client handler stack.

withRequestMiddleware(callable $middleware)

Add new request middleware the client handler stack.

withResponseMiddleware(callable $middleware)

Add new response middleware the client handler stack.

withAttributes(array $attributes)

Set arbitrary attributes to store with the request.

array
attributes()

Get the attributes stored with the request.

withoutTelescope()

Indicate that Telescope should not record this request.

withTelescopeTags(array $tags)

Set Telescope tags for this request.

withTrace()

Indicate that OpenTelemetry should trace this request.

withoutTrace()

Indicate that OpenTelemetry should not trace this request.

withoutTracePropagation()

Indicate that trace context should not be automatically added to this request.

beforeSending(callable $callback)

Add a new "before sending" callback to the request.

afterResponse(callable $callback)

Add a new callback to execute after the response is built.

throw(callable|null $callback = null)

Throw an exception if a server or client error occurs.

throwIf(bool|callable $condition, callable|null $callback = null)

Throw an exception if a server or client error occurred and the given condition evaluates to true.

throwUnless(bool|callable $condition, callable|null $callback = null)

Throw an exception if a server or client error occurred and the given condition evaluates to false.

dump()

Dump the request before sending.

dd()

Dump the request before sending and end the script.

PromiseInterface|Response
get(string $url, Arrayable|array|JsonSerializable|string|null $query = null)

Issue a GET request to the given URL.

PromiseInterface|Response
head(string $url, Arrayable|array|JsonSerializable|string|null $query = null)

Issue a HEAD request to the given URL.

PromiseInterface|Response
query(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a QUERY request to the given URL.

PromiseInterface|Response
post(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a POST request to the given URL.

PromiseInterface|Response
patch(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a PATCH request to the given URL.

PromiseInterface|Response
put(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a PUT request to the given URL.

PromiseInterface|Response
delete(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a DELETE request to the given URL.

PromiseInterface|Response
send(string $method, string $url, array $options = [])

Send the request to the given URL.

string
expandUrlParameters(string $url)

Substitute the URL parameters in the given URL.

array
parseHttpOptions(array $options)

Parse the given HTTP options and set the appropriate additional options.

array
parseMultipartBodyFormat(array $data)

Parse multi-part form data.

array
wrapMultipartStreams(array $multipart)

Wrap the multipart stream resources in PSR-7 streams so they are not closed between retry attempts.

void
rewindMultipartStreams(array $options)

Rewind the seekable multipart streams so each attempt contains the full part contents.

PromiseInterface
makePromise(string $method, string $url, array $options = [], int $attempt = 1)

Send an asynchronous request to the given URL.

mixed
handlePromiseResponse(Response|Throwable $response, string $method, string $url, array $options, int $attempt)

Handle the response of an asynchronous request.

int
getMaximumAttempts()

Get the maximum number of attempts for the request.

int|float
retryDelayInMilliseconds(int $attempt, mixed $exception)

Get the delay in milliseconds before the next retry attempt.

PromiseInterface|ResponseInterface
sendRequest(string $method, string $url, array $options = [])

Send a request either synchronously or asynchronously.

array
parseRequestData(string $method, string $url, array $options)

Get the request data as an array so that we can attach it to the request for convenient assertions.

array
normalizeRequestOptions(array $options)

Normalize the given request options.

array
normalizeHeaderValues(array $headers)

Normalize the given header values.

string|array
normalizeHeaderValue(mixed $value)

Normalize the given header value.

array
normalizeNonFiniteFloatValues(array $values)

Normalize non-finite floats within a nested array.

array
normalizeMultipartOption(array $multipart)

Normalize the given multipart option.

array
normalizeMultipartHeaders(array $multipart)

Normalize the given multipart headers.

mixed
normalizeRequestOptionValue(mixed $value)

Normalize the given request option value.

array|string|null
normalizeQuery(mixed $query)

Normalize a query supplied to a GET request.

mixed
normalizeStructuredDataValue(mixed $value)

Normalize nested structured data values.

string
normalizeScalarString(bool|float|int|string $value)

Normalize a scalar to a string without triggering PHP 8.5 non-finite float warnings.

void
ensureValidRequestBody(mixed $body)

Ensure the given request body can be passed to Guzzle.

populateResponse(Response $response)

Populate the given response with additional data.

ClientInterface
buildClient()

Build the Guzzle client.

ClientInterface
createClient(HandlerStack $handlerStack)

Create a new Guzzle client.

HandlerStack
buildHandlerStack()

Build the Guzzle client handler stack.

callable
newIsolatedHandler()

Create a request-owned transport for destination pinning.

HandlerStack
pushHandlers(HandlerStack $handlerStack)

Add the necessary handlers to the given handler stack.

buildPreparedBodyHandler()

Build the prepared body tracking handler.

buildBeforeSendingHandler()

Build the before sending handler.

buildRecorderHandler()

Build the recorder handler.

buildStubHandler()

Build the stub handler.

sinkStubHandler(mixed $sink)

Get the sink stub handler callback.

buildDatabaseReleaseHandler()

Return idle database sessions before waiting for an external service.

buildDestinationPolicyHandler()

Build the destination policy handler.

PromiseInterface
sendToPolicyDestination(callable $handler, DestinationPolicy $policy, RequestInterface $request, array $options)

Send one physical request to the addresses the destination policy vetted.

RequestInterface
runBeforeSendingCallbacks(RequestInterface $request, array $options)

Execute the "before sending" callbacks.

array
mergeOptions(...$options)

Replace the given options with the current request options.

newResponse(ResponseInterface $response)

Create a new response instance using the given PSR response.

runAfterResponseCallbacks(Response $response)

Execute the "after response" callbacks.

stub(callable|Collection $callback)

Register a stub callable that will intercept requests and be able to return stub responses.

preventStrayRequests(bool $prevent = true)

Indicate that an exception should be thrown if any request is not faked.

allowStrayRequests(array $only)

Allow stray, unfaked requests for specific URL patterns.

bool
isAllowedRequestUrl(string $url)

Determine if the given URL is allowed as a stray request.

async(bool $async = true)

Toggle asynchronicity in requests.

PromiseInterface|null
getPromise()

Retrieve the pending request promise.

void
dispatchRequestSendingEvent()

Dispatch the RequestSending event if a dispatcher is available.

void
dispatchResponseReceivedEvent(Response $response)

Dispatch the ResponseReceived event if a dispatcher is available.

void
dispatchConnectionFailedEvent(Request $request, ConnectionException $exception)

Dispatch the ConnectionFailed event if a dispatcher is available.

truncateExceptionsAt(int $length)

Indicate that request exceptions should be truncated to the given length.

dontTruncateExceptions()

Indicate that request exceptions should not be truncated.

ResponseInterface|null
responseFromException(Throwable $e)

Get the PSR-7 response carried by the given exception, if any.

void
marshalTransportException(TransferException $e)

Handle the given transport exception.

void
marshalTransportExceptionWithResponse(TransferException $e, ResponseInterface $response)

Handle the given transport exception that carried a response.

marshalAsyncTransportExceptionWithResponse(Throwable $e, ResponseInterface $response)

Preserve an asynchronous transfer failure even when its response status is successful.

setClient(ClientInterface $client)

Set the client instance.

setHandler(callable $handler)

Create a new client instance using the given handler.

array
getOptions()

Get the pending request options.

connection(string $connection, array|null $config = null)

Set the pending request connection.

string|null
getConnection()

Get the pending request connection.

array|null
getConnectionConfig()

Get the pending request connection configuration.

array
connectionOptions()

Get the effective request-option preset for the selected connection.

array
mergeOptionLayers(array ...$layers)

Merge HTTP option layers using the request-option merge rules.

mixed
mergeOptionValue(mixed $current, mixed $value, bool $mergeable = false)

Merge an option value from a later layer over the current value.

void
validateRequestOptions(array $options, string $source)

Reject options whose ownership belongs to dedicated APIs.

static void
flushState()

Flush all static state.

Details

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Macroable at line 30
static void macro(string $name, callable|object $macro)

Register a custom macro.

Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 44
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 61
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 72
static void flushMacros()

Flush the existing macros.

Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 83
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 108
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 274
__construct(Factory|null $factory = null, array $middleware = [], array $options = [])

Create a new HTTP Client instance.

Parameters

Factory|null $factory
array $middleware
array $options

at line 310
PendingRequest baseUrl(string $url)

Set the base URL for the pending request.

Parameters

string $url

Return Value

PendingRequest

at line 325
PendingRequest withBody(mixed $content, string|null $contentType = 'application/json')

Attach a raw body to the request.

Parameters

mixed $content
string|null $contentType

Return Value

PendingRequest

Exceptions

InvalidArgumentException

at line 347
PendingRequest asJson()

Indicate the request contains JSON.

Return Value

PendingRequest

at line 357
PendingRequest asForm()

Indicate the request contains form parameters.

Return Value

PendingRequest

at line 368
PendingRequest attach(array|string $name, resource|string $contents = '', string|null $filename = null, array $headers = [])

Attach a file to the request.

Parameters

array|string $name
resource|string $contents
string|null $filename
array $headers

Return Value

PendingRequest

at line 404
PendingRequest asMultipart()

Indicate the request is a multi-part form request.

Return Value

PendingRequest

at line 414
PendingRequest bodyFormat(string $format)

Specify the body format of the request.

Parameters

string $format

Return Value

PendingRequest

at line 426
PendingRequest withQueryParameters(array $parameters)

Set the given query parameters in the request URI.

Parameters

array $parameters

Return Value

PendingRequest

at line 440
PendingRequest contentType(string $contentType)

Specify the request's content type.

Parameters

string $contentType

Return Value

PendingRequest

at line 452
PendingRequest acceptJson()

Indicate that JSON should be returned by the server.

Return Value

PendingRequest

at line 462
PendingRequest accept(string $contentType)

Indicate the type of content that should be returned by the server.

Parameters

string $contentType

Return Value

PendingRequest

at line 472
PendingRequest withHeaders(array $headers)

Add the given headers to the request.

Parameters

array $headers

Return Value

PendingRequest

at line 486
PendingRequest withHeader(string $name, mixed $value)

Add the given header to the request.

Parameters

string $name
mixed $value

Return Value

PendingRequest

at line 496
PendingRequest replaceHeaders(array $headers)

Replace the given headers on the request.

Parameters

array $headers

Return Value

PendingRequest

at line 508
PendingRequest withBasicAuth(string $username, string $password)

Specify the basic authentication username and password for the request.

Parameters

string $username
string $password

Return Value

PendingRequest

at line 520
PendingRequest withDigestAuth(string $username, string $password)

Specify the digest authentication username and password for the request.

Parameters

string $username
string $password

Return Value

PendingRequest

at line 534
PendingRequest withToken(string $token, string $type = 'Bearer')

Specify an authorization token for the request.

Parameters

string $token
string $type

Return Value

PendingRequest

at line 546
PendingRequest withUserAgent(bool|string $userAgent)

Specify the user agent for the request.

Parameters

bool|string $userAgent

Return Value

PendingRequest

at line 558
PendingRequest withUrlParameters(array $parameters = [])

Specify the URL parameters that can be substituted into the request URL.

Parameters

array $parameters

Return Value

PendingRequest

at line 571
PendingRequest withCookie(SetCookie $cookie)

Specify a cookie and its attributes for the request.

Parameters

SetCookie $cookie

Return Value

PendingRequest

at line 591
PendingRequest withCookies(array $cookies, string $domain)

Specify the cookies that should be included with the request.

Parameters

array $cookies
string $domain

Return Value

PendingRequest

at line 605
PendingRequest maxRedirects(int $max)

Specify the maximum number of redirects to allow.

Parameters

int $max

Return Value

PendingRequest

at line 623
PendingRequest withoutRedirecting()

Indicate that redirects should not be followed.

Return Value

PendingRequest

at line 635
PendingRequest withoutVerifying()

Indicate that TLS certificates should not be verified.

Return Value

PendingRequest

at line 651
PendingRequest withDestinationPolicy(DestinationPolicy $policy)

Restrict the request's destinations to those the given policy allows.

The policy checks and pins every physical request, including each redirect, to the addresses it vetted. Faked requests and clients supplied through setClient() never reach it.

Parameters

DestinationPolicy $policy

Return Value

PendingRequest

at line 665
ResolvedDestination resolveDestination(DestinationPolicy $policy, string $url)

internal  
 

Resolve and pin a destination within this request's timeout limits.

Hostname pins use an isolated transport; literal addresses can reuse connections. Disable automatic redirects and send the returned URI so its hostname matches the pins.

Parameters

DestinationPolicy $policy
string $url

Return Value

ResolvedDestination

at line 695
PendingRequest sink(resource|StreamInterface|string $to)

Specify the path where the body of the response should be stored.

Parameters

resource|StreamInterface|string $to

Return Value

PendingRequest

at line 707
PendingRequest timeout(float|int $seconds)

Specify the timeout (in seconds) for the request.

Parameters

float|int $seconds

Return Value

PendingRequest

at line 719
PendingRequest connectTimeout(float|int $seconds)

Specify the connect timeout (in seconds) for the request.

Parameters

float|int $seconds

Return Value

PendingRequest

at line 733
PendingRequest retry(array|int $times, Closure|int $sleepMilliseconds = 0, callable|null $when = null, bool $throw = true)

Specify the number of times the request should be attempted.

Parameters

array|int $times
Closure|int $sleepMilliseconds
callable|null $when
bool $throw

Return Value

PendingRequest

at line 752
PendingRequest withOptions(array $options)

Replace the specified options on the request.

Parameters

array $options

Return Value

PendingRequest

at line 765
PendingRequest withMiddleware(callable $middleware)

Add new middleware the client handler stack.

Parameters

callable $middleware

Return Value

PendingRequest

at line 777
PendingRequest prependMiddleware(callable $middleware)

Prepend new middleware to the client handler stack.

Parameters

callable $middleware

Return Value

PendingRequest

at line 789
PendingRequest withRequestMiddleware(callable $middleware)

Add new request middleware the client handler stack.

Parameters

callable $middleware

Return Value

PendingRequest

at line 801
PendingRequest withResponseMiddleware(callable $middleware)

Add new response middleware the client handler stack.

Parameters

callable $middleware

Return Value

PendingRequest

at line 813
PendingRequest withAttributes(array $attributes)

Set arbitrary attributes to store with the request.

Parameters

array $attributes

Return Value

PendingRequest

at line 823
array attributes()

Get the attributes stored with the request.

Return Value

array

at line 833
PendingRequest withoutTelescope()

Indicate that Telescope should not record this request.

Return Value

PendingRequest

at line 844
PendingRequest withTelescopeTags(array $tags)

Set Telescope tags for this request.

Parameters

array $tags

Return Value

PendingRequest

at line 854
PendingRequest withTrace()

Indicate that OpenTelemetry should trace this request.

Return Value

PendingRequest

at line 864
PendingRequest withoutTrace()

Indicate that OpenTelemetry should not trace this request.

Return Value

PendingRequest

at line 876
PendingRequest withoutTracePropagation()

Indicate that trace context should not be automatically added to this request.

The request may still be traced locally.

Return Value

PendingRequest

at line 886
PendingRequest beforeSending(callable $callback)

Add a new "before sending" callback to the request.

Parameters

callable $callback

Return Value

PendingRequest

at line 899
PendingRequest afterResponse(callable $callback)

Add a new callback to execute after the response is built.

Parameters

callable $callback

Return Value

PendingRequest

at line 912
PendingRequest throw(callable|null $callback = null)

Throw an exception if a server or client error occurs.

Parameters

callable|null $callback

Return Value

PendingRequest

at line 925
PendingRequest throwIf(bool|callable $condition, callable|null $callback = null)

Throw an exception if a server or client error occurred and the given condition evaluates to true.

Parameters

bool|callable $condition
callable|null $callback

Return Value

PendingRequest

at line 940
PendingRequest throwUnless(bool|callable $condition, callable|null $callback = null)

Throw an exception if a server or client error occurred and the given condition evaluates to false.

Parameters

bool|callable $condition
callable|null $callback

Return Value

PendingRequest

at line 954
PendingRequest dump()

Dump the request before sending.

Return Value

PendingRequest

at line 970
PendingRequest dd()

Dump the request before sending and end the script.

Return Value

PendingRequest

at line 992
PromiseInterface|Response get(string $url, Arrayable|array|JsonSerializable|string|null $query = null)

Issue a GET request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable|string|null $query

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
RequestException
InvalidArgumentException

at line 1012
PromiseInterface|Response head(string $url, Arrayable|array|JsonSerializable|string|null $query = null)

Issue a HEAD request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable|string|null $query

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
RequestException
InvalidArgumentException

at line 1032
PromiseInterface|Response query(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a QUERY request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable $data

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
RequestException
InvalidArgumentException

at line 1048
PromiseInterface|Response post(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a POST request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable $data

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
RequestException
InvalidArgumentException

at line 1064
PromiseInterface|Response patch(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a PATCH request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable $data

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
RequestException
InvalidArgumentException

at line 1080
PromiseInterface|Response put(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a PUT request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable $data

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
RequestException
InvalidArgumentException

at line 1096
PromiseInterface|Response delete(string $url, Arrayable|array|JsonSerializable $data = [])

Issue a DELETE request to the given URL.

Parameters

string $url
Arrayable|array|JsonSerializable $data

Return Value

PromiseInterface|Response

Exceptions

ConnectionException
RequestException
InvalidArgumentException

at line 1121
PromiseInterface|Response send(string $method, string $url, array $options = [])

Send the request to the given URL.

Parameters

string $method
string $url
array $options

Return Value

PromiseInterface|Response

Exceptions

Exception
Throwable
InvalidArgumentException

at line 1219
protected string expandUrlParameters(string $url)

Substitute the URL parameters in the given URL.

Parameters

string $url

Return Value

string

at line 1233
protected array parseHttpOptions(array $options)

Parse the given HTTP options and set the appropriate additional options.

Parameters

array $options

Return Value

array

Exceptions

InvalidArgumentException

at line 1281
protected array parseMultipartBodyFormat(array $data)

Parse multi-part form data.

Parameters

array $data

Return Value

array

at line 1299
protected array wrapMultipartStreams(array $multipart)

Wrap the multipart stream resources in PSR-7 streams so they are not closed between retry attempts.

Parameters

array $multipart

Return Value

array

at line 1326
protected void rewindMultipartStreams(array $options)

Rewind the seekable multipart streams so each attempt contains the full part contents.

Parameters

array $options

Return Value

void

at line 1346
protected PromiseInterface makePromise(string $method, string $url, array $options = [], int $attempt = 1)

Send an asynchronous request to the given URL.

Parameters

string $method
string $url
array $options
int $attempt

Return Value

PromiseInterface

Exceptions

Exception

at line 1404
protected mixed handlePromiseResponse(Response|Throwable $response, string $method, string $url, array $options, int $attempt)

Handle the response of an asynchronous request.

Parameters

Response|Throwable $response
string $method
string $url
array $options
int $attempt

Return Value

mixed

Exceptions

Exception

at line 1468
protected int getMaximumAttempts()

Get the maximum number of attempts for the request.

Return Value

int

at line 1478
protected int|float retryDelayInMilliseconds(int $attempt, mixed $exception)

Get the delay in milliseconds before the next retry attempt.

Parameters

int $attempt
mixed $exception

Return Value

int|float

at line 1490
protected PromiseInterface|ResponseInterface sendRequest(string $method, string $url, array $options = [])

Send a request either synchronously or asynchronously.

Parameters

string $method
string $url
array $options

Return Value

PromiseInterface|ResponseInterface

Exceptions

Exception

at line 1548
protected array parseRequestData(string $method, string $url, array $options)

Get the request data as an array so that we can attach it to the request for convenient assertions.

Parameters

string $method
string $url
array $options

Return Value

array

at line 1587
protected array normalizeRequestOptions(array $options)

Normalize the given request options.

Parameters

array $options

Return Value

array

Exceptions

InvalidArgumentException

at line 1647
protected array normalizeHeaderValues(array $headers)

Normalize the given header values.

Parameters

array $headers

Return Value

array

at line 1668
protected string|array normalizeHeaderValue(mixed $value)

Normalize the given header value.

Parameters

mixed $value

Return Value

string|array

Exceptions

InvalidArgumentException

at line 1701
protected array normalizeNonFiniteFloatValues(array $values)

Normalize non-finite floats within a nested array.

Parameters

array $values

Return Value

array

at line 1717
protected array normalizeMultipartOption(array $multipart)

Normalize the given multipart option.

Parameters

array $multipart

Return Value

array

at line 1760
protected array normalizeMultipartHeaders(array $multipart)

Normalize the given multipart headers.

Parameters

array $multipart

Return Value

array

Exceptions

InvalidArgumentException

at line 1787
protected mixed normalizeRequestOptionValue(mixed $value)

Normalize the given request option value.

Parameters

mixed $value

Return Value

mixed

at line 1815
protected array|string|null normalizeQuery(mixed $query)

Normalize a query supplied to a GET request.

Parameters

mixed $query

Return Value

array|string|null

Exceptions

InvalidArgumentException

at line 1829
protected mixed normalizeStructuredDataValue(mixed $value)

Normalize nested structured data values.

Parameters

mixed $value

Return Value

mixed

at line 1855
protected string normalizeScalarString(bool|float|int|string $value)

Normalize a scalar to a string without triggering PHP 8.5 non-finite float warnings.

Parameters

bool|float|int|string $value

Return Value

string

at line 1873
protected void ensureValidRequestBody(mixed $body)

Ensure the given request body can be passed to Guzzle.

Parameters

mixed $body

Return Value

void

Exceptions

InvalidArgumentException

at line 1883
protected Response populateResponse(Response $response)

Populate the given response with additional data.

Parameters

Response $response

Return Value

Response

at line 1895
ClientInterface buildClient()

Build the Guzzle client.

Return Value

ClientInterface

at line 1903
ClientInterface createClient(HandlerStack $handlerStack)

Create a new Guzzle client.

Parameters

HandlerStack $handlerStack

Return Value

ClientInterface

at line 1914
HandlerStack buildHandlerStack()

Build the Guzzle client handler stack.

Return Value

HandlerStack

at line 1955
protected callable newIsolatedHandler()

Create a request-owned transport for destination pinning.

Return Value

callable

at line 1964
HandlerStack pushHandlers(HandlerStack $handlerStack)

Add the necessary handlers to the given handler stack.

Parameters

HandlerStack $handlerStack

Return Value

HandlerStack

at line 1991
protected Closure buildPreparedBodyHandler()

Build the prepared body tracking handler.

Return Value

Closure

at line 2005
Closure buildBeforeSendingHandler()

Build the before sending handler.

Return Value

Closure

at line 2030
Closure buildRecorderHandler()

Build the recorder handler.

Return Value

Closure

at line 2069
Closure buildStubHandler()

Build the stub handler.

Return Value

Closure

Exceptions

StrayRequestException

at line 2130
protected Closure sinkStubHandler(mixed $sink)

Get the sink stub handler callback.

A sink that stops accepting the body fails the request as a transport would, with the response, so the callback also takes the request. A subclass decorating the callback may still pass the response alone, as Laravel's callback takes it; the request being sent is used then.

Parameters

mixed $sink

Return Value

Closure

at line 2187
protected Closure buildDatabaseReleaseHandler()

Return idle database sessions before waiting for an external service.

Return Value

Closure

at line 2195
protected Closure buildDestinationPolicyHandler()

Build the destination policy handler.

Return Value

Closure

at line 2220
protected PromiseInterface sendToPolicyDestination(callable $handler, DestinationPolicy $policy, RequestInterface $request, array $options)

Send one physical request to the addresses the destination policy vetted.

Parameters

callable $handler
DestinationPolicy $policy
RequestInterface $request
array $options

Return Value

PromiseInterface

Exceptions

ConnectionException
DestinationPolicyException
DisallowedDestinationException

at line 2353
RequestInterface runBeforeSendingCallbacks(RequestInterface $request, array $options)

Execute the "before sending" callbacks.

Parameters

RequestInterface $request
array $options

Return Value

RequestInterface

at line 2400
array mergeOptions(...$options)

Replace the given options with the current request options.

Parameters

...$options

Return Value

array

at line 2421
protected Response newResponse(ResponseInterface $response)

Create a new response instance using the given PSR response.

Parameters

ResponseInterface $response

Return Value

Response

at line 2437
protected Response runAfterResponseCallbacks(Response $response)

Execute the "after response" callbacks.

Parameters

Response $response

Return Value

Response

at line 2455
PendingRequest stub(callable|Collection $callback)

Register a stub callable that will intercept requests and be able to return stub responses.

Parameters

callable|Collection $callback

Return Value

PendingRequest

at line 2469
PendingRequest preventStrayRequests(bool $prevent = true)

Indicate that an exception should be thrown if any request is not faked.

Parameters

bool $prevent

Return Value

PendingRequest

at line 2481
PendingRequest allowStrayRequests(array $only)

Allow stray, unfaked requests for specific URL patterns.

Parameters

array $only

Return Value

PendingRequest

at line 2491
bool isAllowedRequestUrl(string $url)

Determine if the given URL is allowed as a stray request.

Parameters

string $url

Return Value

bool

at line 2517
PendingRequest async(bool $async = true)

Toggle asynchronicity in requests.

Parameters

bool $async

Return Value

PendingRequest

at line 2528
PromiseInterface|null getPromise()

Retrieve the pending request promise.

Return Value

PromiseInterface|null

at line 2536
protected void dispatchRequestSendingEvent()

Dispatch the RequestSending event if a dispatcher is available.

Return Value

void

at line 2546
protected void dispatchResponseReceivedEvent(Response $response)

Dispatch the ResponseReceived event if a dispatcher is available.

Parameters

Response $response

Return Value

void

at line 2558
protected void dispatchConnectionFailedEvent(Request $request, ConnectionException $exception)

Dispatch the ConnectionFailed event if a dispatcher is available.

Parameters

Request $request
ConnectionException $exception

Return Value

void

at line 2570
PendingRequest truncateExceptionsAt(int $length)

Indicate that request exceptions should be truncated to the given length.

Parameters

int $length

Return Value

PendingRequest

at line 2582
PendingRequest dontTruncateExceptions()

Indicate that request exceptions should not be truncated.

Return Value

PendingRequest

at line 2592
protected ResponseInterface|null responseFromException(Throwable $e)

Get the PSR-7 response carried by the given exception, if any.

Parameters

Throwable $e

Return Value

ResponseInterface|null

at line 2602
protected void marshalTransportException(TransferException $e)

Handle the given transport exception.

Parameters

TransferException $e

Return Value

void

Exceptions

ConnectionException

at line 2619
protected void marshalTransportExceptionWithResponse(TransferException $e, ResponseInterface $response)

Handle the given transport exception that carried a response.

Parameters

TransferException $e
ResponseInterface $response

Return Value

void

Exceptions

ConnectionException
RequestException

at line 2629
protected Response|ConnectionException marshalAsyncTransportExceptionWithResponse(Throwable $e, ResponseInterface $response)

Preserve an asynchronous transfer failure even when its response status is successful.

Parameters

Throwable $e
ResponseInterface $response

Return Value

Response|ConnectionException

at line 2643
PendingRequest setClient(ClientInterface $client)

Set the client instance.

The client owns its whole handler stack, so destination policies do not apply to it.

Parameters

ClientInterface $client

Return Value

PendingRequest

at line 2657
PendingRequest setHandler(callable $handler)

Create a new client instance using the given handler.

Destination-restricted requests reject custom handlers, since their pins only bind the cURL handler.

Parameters

callable $handler

Return Value

PendingRequest

at line 2667
array getOptions()

Get the pending request options.

Return Value

array

at line 2681
PendingRequest connection(string $connection, array|null $config = null)

Set the pending request connection.

Parameters

string $connection
array|null $config

Return Value

PendingRequest

at line 2700
string|null getConnection()

Get the pending request connection.

Return Value

string|null

at line 2708
array|null getConnectionConfig()

Get the pending request connection configuration.

Return Value

array|null

at line 2716
protected array connectionOptions()

Get the effective request-option preset for the selected connection.

Return Value

array

at line 2732
protected array mergeOptionLayers(array ...$layers)

Merge HTTP option layers using the request-option merge rules.

Parameters

array ...$layers

Return Value

array

at line 2757
protected mixed mergeOptionValue(mixed $current, mixed $value, bool $mergeable = false)

Merge an option value from a later layer over the current value.

Maps merge by key, with later values winning. Lists such as header values, auth credentials and redirect protocols are replaced whole, since merging them by index would mix entries from both layers. The lists of a mergeable option, such as multipart parts, accumulate instead.

Parameters

mixed $current
mixed $value
bool $mergeable

Return Value

mixed

at line 2792
protected void validateRequestOptions(array $options, string $source)

Reject options whose ownership belongs to dedicated APIs.

Parameters

array $options
string $source

Return Value

void

at line 2800
static void flushState()

Flush all static state.

Return Value

void