cakephp/cakephp — pull request #748 by ceeram (2012-08-01 13:54:44+00:00)
Title: 2.3 response

According to http specs, when response has 405 statuscode, the Allow header is required

http://tools.ietf.org/html/rfc2616#section-14.7

Currently when rendering exceptions the response object isnt reused, but a new instance is created.

The pull request would fix that, but maybe would be better to use a clean response object and find anotehr way to handle the Allow header to be set.

Example code:

public function delete($id = null) {
if (!$this->request->is('post')) {
$this->response->header('Allow', 'POST');// this header will be lost!
throw new MethodNotAllowedException();
}
$this->Post->id = $id;
if (!$this->Post->exists()) {
throw new NotFoundException(__('Invalid post'));
}
if ($this->Post->delete()) {
$this->Session->setFlash(__('Post deleted'));
$this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Post was not deleted'));
$this->redirect(array('action' => 'index'));
}

Also maybe we could implement CakeRequest::allow($methods) not matter which way we set the Allow header.

The allow() method would check $this->is($method); for every method, and automatically set the correct Allow header, and throw the MethodNotAllowedException() ??