green-turtle/content-encoding

There is no license information available for the latest version (1.0.0) of this package.

1.0.0 2023-12-12 18:21 UTC

This package is auto-updated.

Last update: 2024-12-13 16:51:51 UTC


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...
];