Skip to content

Commit

Permalink
Merge pull request #4 from shadowhand/fix/allow-header
Browse files Browse the repository at this point in the history
Send Allow header when method is not allowed
  • Loading branch information
oscarotero committed Apr 13, 2017
2 parents c5f4265 + ca03043 commit 6a23e9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/FastRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions tests/FastRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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()
Expand Down

0 comments on commit 6a23e9e

Please sign in to comment.