Skip to content

Commit

Permalink
Add compression middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
phpbg committed Oct 20, 2018
1 parent 53db862 commit c43b4b2
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 30 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"zendframework/zend-filter": "^2.8",
"psr/log": "^1.0",
"psr/http-message": "^1.0",
"react/promise": "^2.7"
"react/promise": "^2.7",
"christoph-kluge/reactphp-http-response-compression-middleware": "dev-master"
},
"suggest": {
"wyrihaximus/react-http-middleware-session": "session handling"
Expand All @@ -33,4 +34,4 @@
"PhpBg\\MiniHttpd\\": "src"
}
}
}
}
198 changes: 178 additions & 20 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions example/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
// You can share your PSR3 logger here
$applicationContext->logger = new \PhpBg\MiniHttpd\Logger\Console(\Psr\Log\LogLevel::DEBUG);

$mimeDb = new \PhpBg\MiniHttpd\MimeDb\MimeDb($applicationContext->logger);

$server = new \React\Http\Server([
// Log all incoming requests
new \PhpBg\MiniHttpd\Middleware\LogRequest($applicationContext->logger),
Expand All @@ -57,6 +59,12 @@
// Decode once uri path
new \PhpBg\MiniHttpd\Middleware\UriPath(),

// Compress compressible responses
new \PhpBg\MiniHttpd\Middleware\ResponseCompressionMiddleware([
new \Sikei\React\Http\Middleware\CompressionGzipHandler(new \Sikei\React\Http\Middleware\Detector\ArrayDetector($mimeDb->getCompressible())),
new \Sikei\React\Http\Middleware\CompressionDeflateHandler(new \Sikei\React\Http\Middleware\Detector\ArrayDetector($mimeDb->getCompressible())),
]),

// Serve static files
new \PhpBg\MiniHttpd\Middleware\StaticContent($applicationContext->publicPath, $applicationContext->logger),

Expand Down
Loading

0 comments on commit c43b4b2

Please sign in to comment.