green-turtle / content-encoding
Requires
- php: ^8.1.0
- ext-zlib: *
- illuminate/http: ^9.0 || ^10.0
- illuminate/support: ^9.0 || ^10.0
- symfony/psr-http-message-bridge: ^2.1
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.7
README
Middleware that encodes response content.
Reduces data sent out, reduces bandwidth used.
Installation
composer require green-turtle/content-encoding
Configuration
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"
Encode Unknown Types
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,
Allowed Types
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\/.*)(;.*)?$#' ]
Encoders
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
Global Usage
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... ];