Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating RequestHandlerComponent to accept body of HTTP Delete requests #4108

Merged
merged 2 commits into from Jul 30, 2014
Merged

Updating RequestHandlerComponent to accept body of HTTP Delete requests #4108

merged 2 commits into from Jul 30, 2014

Conversation

stevetauber
Copy link
Contributor

I was trying to use HTTP DELETE along with a JSON encoded body. CakePHP was ignoring the body content while it works for POST and PUT. I traced it down to this line of code.

During startup, the RequestHandlerComponent tries to set $controller->request->data if the requestedType is valid. This was not occurring for DELETE requests because of the checks in requestedWith
https://github.com/cakephp/cakephp/blob/master/lib/Cake/Controller/Component/RequestHandlerComponent.php#L216

I've patched requestedWith to allow DELETE. There are considerable arguments why the body of a DELETE request should be allowed, the strongest being that it the RFC allows it. Here is a stack overflow discussion of that issue at hand:

http://stackoverflow.com/questions/14323716/restful-alternatives-to-delete-request-body

@ADmad
Copy link
Member

ADmad commented Jul 29, 2014

Seems reasonable to me. Can you please add tests for this. Though unsure if this should goto into 2.5 or 2.6.

@markstory markstory added this to the 2.5.4 milestone Jul 29, 2014
@markstory
Copy link
Member

Seems reasonable to include in 2.5 as I would expect the HTTP verb to not impact how JSON is deserialized.

@stevetauber
Copy link
Contributor Author

Okay, I've added an assert in what I believe to be the correct existing unit test function. I would like to mention that one for PUT happens to be missing, but I did not add that.

@@ -601,6 +601,9 @@ public function testRequestContentTypes() {
$result = $this->RequestHandler->requestedWith(array('rss', 'atom'));
$this->assertFalse($result);

$_SERVER['REQUEST_METHOD'] = 'DELETE';
$this->assertEquals('json', $this->RequestHandler->requestedWith());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off, but I can fix that post merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies; I think I have spaces on instead of tabs :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it should be tab indentation.

@markstory markstory merged commit e6f6ded into cakephp:master Jul 30, 2014
markstory added a commit that referenced this pull request Jul 30, 2014
@markstory
Copy link
Member

Thanks 👍

@ravage84
Copy link
Member

ravage84 commented Aug 6, 2014

Sorry for being late to the disusscion, but I agree with @ADmad, this should have gone into 2.6 as it adds functionality.
Nobody got hurt, though ;-)

@ADmad
Copy link
Member

ADmad commented Aug 6, 2014

@ravage84 Don't augment my response, I never said that it should have gone to 2.6 :) My comment said "unsure if this should go into 2.5 or 2.6". Mark decided it can go to 2.5 and I am fine with that.

@ravage84
Copy link
Member

ravage84 commented Aug 6, 2014

@ADmad sorry, wasn't my intend.

@markstory
Copy link
Member

I see this as a mistake not a new feature, which is why it went into 2.5

hmic pushed a commit to hmic/cakephp that referenced this pull request Aug 24, 2014
Fix fields cache to depend on the schemaName as well.

Fixes cakephp#4108
hmic pushed a commit to hmic/cakephp that referenced this pull request Aug 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants