middlewares/encoder

Middleware to encode the response body to gzip or deflate

v1.1.0 2018-08-04 10:41 UTC

README

Latest Version on Packagist Software License Build Status Quality Score Total Downloads SensioLabs Insight

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:

You can use the component ContentEncoding in the middlewares/negotiation to negotiate the encoding to use.

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/encoder.

composer require middlewares/encoder

Example

$dispatcher = new Dispatcher([
	new Middlewares\GzipEncoder(),
]);

$response = $dispatcher->dispatch(new ServerRequest());

GzipEncoder

Compress the response body to GZIP format using gzencode and add the header Content-Encoding: gzip.

Note: The response body is encoded only if the header contains the value gzip in the header Accept-Encoding.

DeflateEncoder

Compress the response body to Deflate format using gzdeflate and add the header Content-Encoding: deflate.

Note: The response body is encoded only if the header contains the value deflate in the header Accept-Encoding.

Options

streamFactory(Psr\Http\Message\StreamFactoryInterface $streamFactory)

A PSR-17 factory to create the response bodies.

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

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