Merge branch 'pr/472-method-not-allowed'

This commit is contained in:
Chris Boden 2016-12-30 13:26:12 -05:00
commit 7a661b5016
2 changed files with 8 additions and 6 deletions

View File

@ -132,7 +132,7 @@ class App {
} }
} }
$this->routes->add('rr-' . ++$this->_routeCounter, new Route($path, array('_controller' => $decorated), array('Origin' => $this->httpHost), array(), $httpHost)); $this->routes->add('rr-' . ++$this->_routeCounter, new Route($path, array('_controller' => $decorated), array('Origin' => $this->httpHost), array(), $httpHost, array(), array('GET')));
return $decorated; return $decorated;
} }

View File

@ -34,7 +34,7 @@ class Router implements HttpServerInterface {
try { try {
$route = $this->_matcher->match($request->getPath()); $route = $this->_matcher->match($request->getPath());
} catch (MethodNotAllowedException $nae) { } catch (MethodNotAllowedException $nae) {
return $this->close($conn, 403); return $this->close($conn, 405, array('Allow' => $nae->getAllowedMethods()));
} catch (ResourceNotFoundException $nfe) { } catch (ResourceNotFoundException $nfe) {
return $this->close($conn, 404); return $this->close($conn, 404);
} }
@ -92,12 +92,14 @@ class Router implements HttpServerInterface {
* Close a connection with an HTTP response * Close a connection with an HTTP response
* @param \Ratchet\ConnectionInterface $conn * @param \Ratchet\ConnectionInterface $conn
* @param int $code HTTP status code * @param int $code HTTP status code
* @param array $additionalHeaders
* @return null * @return null
*/ */
protected function close(ConnectionInterface $conn, $code = 400) { protected function close(ConnectionInterface $conn, $code = 400, array $additionalHeaders = array()) {
$response = new Response($code, array( $headers = array_merge(array(
'X-Powered-By' => \Ratchet\VERSION 'X-Powered-By' => \Ratchet\VERSION
)); ), $additionalHeaders);
$response = new Response($code, $headers);
$conn->send((string)$response); $conn->send((string)$response);
$conn->close(); $conn->close();