Skip to content

Data can be large. Bandwidth is in high demand. Make the most of it.

Notifications You must be signed in to change notification settings

GreenTurtleTech/laravel-content-encoding

Repository files navigation

Laravel Content Encoding Middleware

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

About

Data can be large. Bandwidth is in high demand. Make the most of it.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages