Skip to content

Commit

Permalink
Ensuring the response content type is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Morgan committed Jul 12, 2013
1 parent 089eeb9 commit d84a370
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions code/RestfulServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,15 @@ protected function postHandler($className, $id, $actionName) {
$this->getResponse()->setStatusCode(201); // Created
}

if(isset($result->class)) {
$formatterClass = $result->class;
}
else {
$formatterClass = $className;
}
$responseFormatter = $this->getResponseDataFormatter($formatterClass);
$this->getResponse()->addHeader('Content-Type', $responseFormatter->getOutputContentType());

// Handle validation errors
if($result instanceof ValidationResult) {
return $this->handleValidationError($result, $reqFormatter);
Expand All @@ -581,10 +590,6 @@ protected function postHandler($className, $id, $actionName) {
return $result;
}

$responseFormatter = $this->getResponseDataFormatter($result->class);

$this->getResponse()->addHeader('Content-Type', $responseFormatter->getOutputContentType());

// Append the default extension for the output format to the Location header
// or else we'll use the default (XML)
$types = $responseFormatter->supportedExtensions();
Expand Down

0 comments on commit d84a370

Please sign in to comment.