philsturgeon/codeigniter-restserver — Issue #101: Cannot read format from body in POST calls
Author: jackshakes
Created: 2012-03-02 19:53:20+00:00
State: open

The default library looks like it only searches the GET uri string for the return format. This means if my default format is XML, and I pass the following to a user activate function via the body of a POST request:

1234
json

The return comes back to me in XML format, even though I have specified I want JSON.

To fix this, I modified the _detect_output_format() function (line 348 or so):

The block:

if (isset($this->_get_args['format']) AND array_key_exists($this->_get_args['format'], $this->_supported_formats))
{
return $this->_get_args['format'];
}

becomes:

if (isset($this->_get_args['format']) AND array_key_exists($this->_get_args['format'], $this->_supported_formats))
{
return $this->_get_args['format'];
}
elseif (isset($this->_post_args['format']) AND array_key_exists($this->_post_args['format'], $this->_supported_formats))
{
return $this->_post_args['format'];
}