Registered implicit options middleware

This commit is contained in:
Alejandro Celaya 2017-04-13 09:43:11 +02:00
parent d117f82bcb
commit 596d1ee797
2 changed files with 7 additions and 5 deletions

View file

@ -4,7 +4,7 @@ use Shlinkio\Shlink\Rest\Middleware\BodyParserMiddleware;
use Shlinkio\Shlink\Rest\Middleware\CheckAuthenticationMiddleware; use Shlinkio\Shlink\Rest\Middleware\CheckAuthenticationMiddleware;
use Shlinkio\Shlink\Rest\Middleware\CrossDomainMiddleware; use Shlinkio\Shlink\Rest\Middleware\CrossDomainMiddleware;
use Shlinkio\Shlink\Rest\Middleware\PathVersionMiddleware; use Shlinkio\Shlink\Rest\Middleware\PathVersionMiddleware;
use Zend\Expressive\Container\ApplicationFactory; use Zend\Expressive;
use Zend\Stratigility\Middleware\ErrorHandler; use Zend\Stratigility\Middleware\ErrorHandler;
return [ return [
@ -27,7 +27,7 @@ return [
'routing' => [ 'routing' => [
'middleware' => [ 'middleware' => [
ApplicationFactory::ROUTING_MIDDLEWARE, Expressive\Application::ROUTING_MIDDLEWARE,
], ],
'priority' => 10, 'priority' => 10,
], ],
@ -36,6 +36,7 @@ return [
'path' => '/rest', 'path' => '/rest',
'middleware' => [ 'middleware' => [
CrossDomainMiddleware::class, CrossDomainMiddleware::class,
Expressive\Middleware\ImplicitOptionsMiddleware::class,
BodyParserMiddleware::class, BodyParserMiddleware::class,
CheckAuthenticationMiddleware::class, CheckAuthenticationMiddleware::class,
], ],
@ -44,7 +45,7 @@ return [
'post-routing' => [ 'post-routing' => [
'middleware' => [ 'middleware' => [
ApplicationFactory::DISPATCH_MIDDLEWARE, Expressive\Application::DISPATCH_MIDDLEWARE,
], ],
'priority' => 1, 'priority' => 1,
], ],

View file

@ -1,12 +1,13 @@
<?php <?php
namespace Shlinkio\Shlink\Rest\Middleware; namespace Shlinkio\Shlink\Rest\Middleware;
use Fig\Http\Message\RequestMethodInterface;
use Interop\Http\ServerMiddleware\DelegateInterface; use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface; use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
class CrossDomainMiddleware implements MiddlewareInterface class CrossDomainMiddleware implements MiddlewareInterface, RequestMethodInterface
{ {
/** /**
* Process an incoming server request and return a response, optionally delegating * Process an incoming server request and return a response, optionally delegating
@ -28,7 +29,7 @@ class CrossDomainMiddleware implements MiddlewareInterface
// Add Allow-Origin header // Add Allow-Origin header
$response = $response->withHeader('Access-Control-Allow-Origin', $request->getHeader('Origin')) $response = $response->withHeader('Access-Control-Allow-Origin', $request->getHeader('Origin'))
->withHeader('Access-Control-Expose-Headers', 'Authorization'); ->withHeader('Access-Control-Expose-Headers', 'Authorization');
if ($request->getMethod() !== 'OPTIONS') { if ($request->getMethod() !== self::METHOD_OPTIONS) {
return $response; return $response;
} }