ContentTypePlugin
in package
implements
Plugin
FinalYes
Allow to set the correct content type header on the request automatically only if it is not set.
Tags
Table of Contents
Interfaces
- Plugin
- A plugin is a middleware to transform the request and/or the response.
Properties
- $sizeLimit : int
- Determine the size stream limit for which the detection as to be skipped (default to 16Mb).
- $skipDetection : bool
- Allow to disable the content type detection when stream is too large (as it can consume a lot of resource).
Methods
- __construct() : mixed
- handleRequest() : Promise
- Handle the request and return the response coming from the next callable.
- isJson() : bool
- isXml() : bool
Properties
$sizeLimit
Determine the size stream limit for which the detection as to be skipped (default to 16Mb).
private
int
$sizeLimit
$skipDetection
Allow to disable the content type detection when stream is too large (as it can consume a lot of resource).
private
bool
$skipDetection
true skip the content type detection false detect the content type (default value)
Methods
__construct()
public
__construct([array{'skip_detection'?: bool, 'size_limit'?: int} $config = [] ]) : mixed
Parameters
- $config : array{'skip_detection'?: bool, 'size_limit'?: int} = []
-
Configuration options:
- skip_detection: true skip detection if stream size is bigger than $size_limit
- size_limit: size stream limit for which the detection as to be skipped
handleRequest()
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)
isJson()
private
isJson(StreamInterface $stream) : bool
Parameters
- $stream : StreamInterface
Return values
boolisXml()
private
isXml(StreamInterface $stream) : bool
Parameters
- $stream : StreamInterface