Hi all I am experienceing some weird behaviour on a PUT request (Phalcon 1.3.4)
If I send a body of json data encoded as text/html, I get a response back. If I send a body of json data with Content-Type: application/json I get a null back.
I am not using the micro part here, but a full blown phalcon mvc multi module app.
Here is the controller;
public function updateAction()
{
if ($this->request->isPut()) {
$data = $this->request->getJsonRawBody();
$this->view->disable();
$this->response->setContentType('application/json', 'utf-8');
echo json_encode($data);
}
}
Curl Request
curl 'https://test.dev/profile' -v -X PUT -H 'Content-Type: application/json' -d '{"firstName": "AJ","surname": "McKee"}'
> PUT /profile HTTP/1.1
> User-Agent: curl/7.37.1
> Host: test.dev
> Accept: */*
> Content-Type: application/json
> Content-Length: 38
>
* upload completely sent off: 38 out of 38 bytes
< HTTP/1.1 200 OK
< Date: Fri, 17 Apr 2015 11:36:21 GMT
* Server Apache/2.4.7 (Ubuntu) is not blacklisted
< Server: Apache/2.4.7 (Ubuntu)
< X-Powered-By: PHP/5.5.9-1ubuntu4.6
< Content-Length: 4
< Content-Type: application/json; charset=utf-8
<
* Connection #0 to host test.dev left intact
However setting the Content-Type to text/html seems to work
curl 'https://test.dev/profile' -v -X PUT -H 'Content-Type: text/html' -d '{"firstName": "AJ","surname": "McKee"}'
> PUT /profile HTTP/1.1
> User-Agent: curl/7.37.1
> Host: test.dev
> Accept: */*
> Content-Type: text/html
> Content-Length: 38
>
* upload completely sent off: 38 out of 38 bytes
< HTTP/1.1 200 OK
< Date: Fri, 17 Apr 2015 11:43:03 GMT
* Server Apache/2.4.7 (Ubuntu) is not blacklisted
< Server: Apache/2.4.7 (Ubuntu)
< X-Powered-By: PHP/5.5.9-1ubuntu4.6
< Content-Length: 36
< Content-Type: application/json; charset=utf-8
<
* Connection #0 to host test.dev left intact
{"firstName":"AJ","surname":"McKee"}
As you can see the response when setting the content type to text/html is as expected (Echo back what I send for testing).
What is the correct manner to handle multiple content types in this instance. As some requests will undoubtly send the application/json header.
Is this a feature, or bug within Phalcon or PHP?
Any light you can send on, would be great. TIA