2017 © Pedro Peláez
 

library encoder

Middleware to encode the response body to gzip or deflate

image

middlewares/encoder

Middleware to encode the response body to gzip or deflate

  • Saturday, January 27, 2018
  • by oscarotero
  • Repository
  • 2 Watchers
  • 1 Stars
  • 291 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 77 % Grown

The README.md

middlewares/encoder

Latest Version on Packagist ![Software License][ico-license] Testing ![Total Downloads][ico-downloads], (*1)

Middleware to encode the response body to gzip or deflate if the Accept-Encoding header is present and adds the Content-Encoding header. This package is splitted into the following components:, (*2)

You can use the component ContentEncoding in the middlewares/negotiation to negotiate the encoding to use., (*3)

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/encoder., (*4)

composer require middlewares/encoder

GzipEncoder

Compress the response body to GZIP format using gzencode and add the header Content-Encoding: gzip., (*5)

Note: The response body is encoded only if the header contains the value gzip in the header Accept-Encoding., (*6)

Dispatcher::run([
    new Middlewares\GzipEncoder(),
]);

Optionally, you can provide a Psr\Http\Message\StreamFactoryInterface that will be used to create the response body. If it's not defined, Middleware\Utils\Factory will be used to detect it automatically., (*7)

$streamFactory = new MyOwnStreamFactory();

$encoder = new Middlewares\GzipEncoder($streamFactory);

DeflateEncoder

Compress the response body to Deflate format using gzdeflate and add the header Content-Encoding: deflate., (*8)

Note: The response body is encoded only if the header contains the value deflate in the header Accept-Encoding., (*9)

Dispatcher::run([
    new Middlewares\DeflateEncoder(),
]);

Optionally, you can provide a Psr\Http\Message\StreamFactoryInterface that will be used to create the response body. If it's not defined, Middleware\Utils\Factory will be used to detect it automatically., (*10)

$streamFactory = new MyOwnStreamFactory();

$encoder = new Middlewares\DeflateEncoder($streamFactory);

Common Options

contentType

This option allows the overring of the default patterns used to detect what resources are already compressed., (*11)

The default pattern detects the following mime types text/*, application/json, image/svg+xml and empty content types as compressible. If the pattern begins with a forward slash / it is tested as a regular expression, otherwise its is case-insensitive string comparison., (*12)

Dispatcher::run([
    (new Middlewares\DeflateEncoder())
            ->contentType(
                    '/^application\/pdf$/', // Regular Expression
                    'text/csv' // Text Pattern
            )
]);

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details., (*13)

The MIT License (MIT). Please see LICENSE for more information., (*14)

The Versions

27/01 2018

dev-master

9999999-dev https://github.com/middlewares/encoder

Middleware to encode the response body to gzip or deflate

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 http encoding compression psr-15 gzip deflate

27/01 2018

v1.0.0

1.0.0.0 https://github.com/middlewares/encoder

Middleware to encode the response body to gzip or deflate

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 http encoding compression psr-15 gzip deflate

13/11 2017

v0.5.0

0.5.0.0 https://github.com/middlewares/encoder

Middleware to encode the response body to gzip or deflate

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 http encoding compression psr-15 gzip deflate

21/09 2017

v0.4.0

0.4.0.0 https://github.com/middlewares/encoder

Middleware to encode the response body to gzip or deflate

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 http encoding compression psr-15 gzip deflate

21/09 2017

v0.4.2

0.4.2.0 https://github.com/middlewares/encoder

Middleware to encode the response body to gzip or deflate

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 http encoding compression psr-15 gzip deflate

25/03 2017

v0.3.2

0.3.2.0 https://github.com/middlewares/encoder

Middleware to encode the response body to gzip or deflate

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 http encoding compression psr-15 gzip deflate

22/03 2017

v0.3.1

0.3.1.0 https://github.com/middlewares/encoder

Middleware to encode the response body to gzip or deflate

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 http encoding compression psr-15 gzip deflate

26/12 2016

v0.3.0

0.3.0.0 https://github.com/middlewares/encoder

Middleware to encode the response body to gzip or deflate

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 http encoding compression psr-15 gzip deflate

27/11 2016

v0.2.0

0.2.0.0 https://github.com/middlewares/encoder

Middleware to encode the response body to gzip or deflate

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 http encoding compression psr-15 gzip deflate

11/10 2016

v0.1.0

0.1.0.0 https://github.com/middlewares/encoder

Middleware to encode the response body to gzip or deflate

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 http encoding compression psr-15 gzip deflate