Middleware that encodes response content.
Reduces data sent out, reduces bandwidth used.
composer require green-turtle/content-encoding
The defaults are set in config/content-encoding.php
.
To publish a copy to your own config, use the following:
php artisan vendor:publish --tag="green-turtle-content-encoding"
Sometimes the Content-Type
header may be missing.
You may specify in your config whether you still wish to try encoding data.
By default, it is set to false.
'encode_unknown_type' => false,
These are the types of content allowed to be encoded.
Each type is a string that will be used as a regex pattern.
Example, any text format is acceptable:
'allowed_types' => [ '#^(text\/.*)(;.*)?$#' ]
These are the encoders determine what encodings are supported.
The built-in Encoders are enabled by default:
'encoders' => [
Gzip::class,
Deflate::class,
]
You may create more by implementing the following interface:
GreenTurtle\Middleware\Encoder\ContentEncoder
To enable this middleware globally, add the following to your middleware
array, found within app/Http/Kernel.php
:
For example:
protected $middleware = [
// other middleware...
\GreenTurtle\Middleware\ContentEncoding::class
// other middleware...
];