diff --git a/src/FastRoute.php b/src/FastRoute.php index 92d64d3..76ed9f1 100644 --- a/src/FastRoute.php +++ b/src/FastRoute.php @@ -98,7 +98,7 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele } if ($route[0] === Dispatcher::METHOD_NOT_ALLOWED) { - return Factory::createResponse(405); + return Factory::createResponse(405)->withHeader('Allow', implode(', ', $route[1])); } foreach ($route[2] as $name => $value) { diff --git a/tests/FastRouteTest.php b/tests/FastRouteTest.php index d0bbd75..b20e22b 100644 --- a/tests/FastRouteTest.php +++ b/tests/FastRouteTest.php @@ -67,6 +67,14 @@ public function testFastRouteNotAllowed() $request->getAttribute('id') ); }); + + $r->addRoute('PUT', '/user/{name}/{id:[0-9]+}', function ($request) { + return sprintf( + 'Hello %s (%s)', + $request->getAttribute('name'), + $request->getAttribute('id') + ); + }); }); $request = Factory::createServerRequest([], 'GET', 'http://domain.com/user/oscarotero/35'); @@ -77,6 +85,7 @@ public function testFastRouteNotAllowed() $this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response); $this->assertEquals(405, $response->getStatusCode()); + $this->assertEquals('POST, PUT', $response->getHeaderLine('Allow')); } public function testFastRouteResolver()