<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
christoph-kluge / reactphp-http-response-compression-middleware example snippets
$server = new Server(new MiddlewareRunner([
new ResponseCompressionMiddleware([
new CompressionGzipHandler(),
new CompressionDeflateHandler(),
]),
function (ServerRequestInterface $request, callable $next) {
return new Response(200, ['Content-Type' => 'application/json'], json_encode([
'some' => 'nice',
'json' => 'values',
]));
},
]));
// DefaultRegexDetector.php -> used in __construct()
new RegexDetector([
'/^text\/[a-z-\+]+$/', // text/*
'/^application\/json$/', // application/json
'/^application\/xml$/', // application/xml
'/^[a-z-\+]+\/[a-z-\+]+\+json$/', // */*+json
'/^[a-z-\+]+\/[a-z-\+]+\+xml$/', // */*+xml
]);
new CompressionGzipHandler(new ArrayDetector[
'text/html',
]),
new CompressionGzipHandler(new RegexDetector[
'/^text\/[a-z]+$/',
]),
new CompressionGzipHandler(new class implements MimeDetectorInterface {
public function isCompressible($mime) {
// your custom magic here..
return true;
}
}),
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.