Content-Type shouldn't be sent with HTTP 204?
Another library, Siesta for iOS, expects an HTTP 204 to not include the Content-Type (or, I should say that if that is present, they try to parse the non-existent body).
Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body.
While it doesn't explicitly state that the header shouldn't be sent if there is no body, it only states that it should if the body exists.
I'd suggest moving the Content-Type generation logic after the status code assignment, with it wrapped in a conditional where $code != 204.
Thoughts?
While we think about the long term solution for this problem, you can easily implement a quick fix
Compose class is responsible for final response, so you can create a custom Compose class by implementing iCompose interface and then set Defaults::$composeClass to the class name of your custom class. Here is an example
class CustomCompose implements iCompose
{
public static $includeDebugInfo = true;
public $restler;
public function response($result)
{
if ($this->restler->responseCode == 204) {
return '';
}
return $result;
}
public function message(RestException $exception)
{
$r = array(
'error' => array(
'code' => $exception->getCode(),
'message' => $exception->getErrorMessage(),
) + $exception->getDetails()
);
if (!Scope::get('Restler')->getProductionMode() && self::$includeDebugInfo) {
$r += array(
'debug' => array(
'source' => $exception->getSource(),
'stages' => $exception->getStages(),
)
);
}
return $r;
}
}