RedirectPlugin
in package
implements
Plugin
Follow redirections.
Tags
Table of Contents
Interfaces
- Plugin
- A plugin is a middleware to transform the request and/or the response.
Properties
- $circularDetection : array<string|int, array<string|int, string>>
- $preserveHeader : bool|array<string|int, mixed>
- Determine how header should be preserved from old request.
- $redirectCodes : array<string|int, mixed>
- Rule on how to redirect, change method for the new request.
- $redirectStorage : array<string|int, mixed>
- Store all previous redirect from 301 / 308 status code.
- $streamFactory : StreamFactoryInterface|null
- $useDefaultForMultiple : bool
- Whether the location header must be directly used for a multiple redirection status code (300).
Methods
- __construct() : mixed
- guessStreamFactory() : StreamFactoryInterface|null
- The default only needs to be determined if no value is provided.
- handleRequest() : Promise
- Handle the request and return the response coming from the next callable.
- buildRedirectRequest() : RequestInterface
- createUri() : UriInterface
- Creates a new Uri from the old request and the location header.
Properties
$circularDetection
private
array<string|int, array<string|int, string>>
$circularDetection
= []
Chain identifier => list of URLs for this chain
$preserveHeader
Determine how header should be preserved from old request.
private
bool|array<string|int, mixed>
$preserveHeader
true will keep all previous headers (default value) false will ditch all previous headers string[] will keep only headers with the specified names
$redirectCodes
Rule on how to redirect, change method for the new request.
private
array<string|int, mixed>
$redirectCodes
= [300 => ['switch' => ['unless' => ['GET', 'HEAD'], 'to' => 'GET'], 'multiple' => true, 'permanent' => false], 301 => ['switch' => ['unless' => ['GET', 'HEAD'], 'to' => 'GET'], 'multiple' => false, 'permanent' => true], 302 => ['switch' => ['unless' => ['GET', 'HEAD'], 'to' => 'GET'], 'multiple' => false, 'permanent' => false], 303 => ['switch' => ['unless' => ['GET', 'HEAD'], 'to' => 'GET'], 'multiple' => false, 'permanent' => false], 307 => ['switch' => false, 'multiple' => false, 'permanent' => false], 308 => ['switch' => false, 'multiple' => false, 'permanent' => true]]
$redirectStorage
Store all previous redirect from 301 / 308 status code.
private
array<string|int, mixed>
$redirectStorage
= []
$streamFactory
private
StreamFactoryInterface|null
$streamFactory
$useDefaultForMultiple
Whether the location header must be directly used for a multiple redirection status code (300).
private
bool
$useDefaultForMultiple
Methods
__construct()
public
__construct([array{'preserve_header'?: bool|string[], 'use_default_for_multiple'?: bool, 'strict'?: bool} $config = [] ]) : mixed
Parameters
- $config : array{'preserve_header'?: bool|string[], 'use_default_for_multiple'?: bool, 'strict'?: bool} = []
-
Configuration options:
- preserve_header: True keeps all headers, false remove all of them, an array is interpreted as a list of header names to keep
- use_default_for_multiple: Whether the location header must be directly used for a multiple redirection status code (300)
- strict: When true, redirect codes 300, 301, 302 will not modify request method and body
- stream_factory: If set, must be a PSR-17 StreamFactoryInterface - if not set, we try to discover one
guessStreamFactory()
The default only needs to be determined if no value is provided.
public
guessStreamFactory() : StreamFactoryInterface|null
Return values
StreamFactoryInterface|nullhandleRequest()
Handle the request and return the response coming from the next callable.
public
handleRequest(RequestInterface $request, callable $next, callable $first) : Promise
Parameters
- $request : RequestInterface
- $next : callable
-
Next middleware in the chain, the request is passed as the first argument
- $first : callable
-
First middleware in the chain, used to to restart a request
Return values
Promise —Resolves a PSR-7 Response or fails with an Http\Client\Exception (The same as HttpAsyncClient)
buildRedirectRequest()
private
buildRedirectRequest(RequestInterface $originalRequest, UriInterface $targetUri, int $statusCode) : RequestInterface
Parameters
- $originalRequest : RequestInterface
- $targetUri : UriInterface
- $statusCode : int
Return values
RequestInterfacecreateUri()
Creates a new Uri from the old request and the location header.
private
createUri(ResponseInterface $redirectResponse, RequestInterface $originalRequest) : UriInterface
Parameters
- $redirectResponse : ResponseInterface
- $originalRequest : RequestInterface