added optional powered-by header (#2618)

This commit is contained in:
Daniël Klabbers 2021-03-05 16:05:13 +01:00 committed by GitHub
parent 84ded0ce50
commit 4b0ad6972d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 1 deletions

View File

@ -67,7 +67,8 @@ class ForumServiceProvider extends AbstractServiceProvider
HttpMiddleware\SetLocale::class, HttpMiddleware\SetLocale::class,
'flarum.forum.route_resolver', 'flarum.forum.route_resolver',
HttpMiddleware\CheckCsrfToken::class, HttpMiddleware\CheckCsrfToken::class,
HttpMiddleware\ShareErrorsFromSession::class HttpMiddleware\ShareErrorsFromSession::class,
HttpMiddleware\FlarumPromotionHeader::class,
]; ];
}); });

View File

@ -0,0 +1,37 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Http\Middleware;
use Flarum\Foundation\Config;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface;
class FlarumPromotionHeader implements Middleware
{
protected $enabled = true;
public function __construct(Config $config)
{
$this->enabled = $config['poweredByHeader'] ?? true;
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $handler->handle($request);
if ($this->enabled) {
$response = $response->withAddedHeader('X-Powered-By', 'Flarum');
}
return $response;
}
}

View File

@ -55,6 +55,7 @@ class StoreConfig implements Step, ReversibleStep
{ {
return [ return [
'debug' => $this->debugMode, 'debug' => $this->debugMode,
'poweredByHeader' => true,
'database' => $this->dbConfig->toArray(), 'database' => $this->dbConfig->toArray(),
'url' => (string) $this->baseUrl, 'url' => (string) $this->baseUrl,
'paths' => $this->getPathsConfig(), 'paths' => $this->getPathsConfig(),