From d84a370c54636e1dd0db66109e16b089c29c32f4 Mon Sep 17 00:00:00 2001 From: Will Morgan Date: Fri, 12 Jul 2013 17:06:17 +0100 Subject: [PATCH] Ensuring the response content type is correct --- code/RestfulServer.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/code/RestfulServer.php b/code/RestfulServer.php index b0bd0ff..800fe5d 100644 --- a/code/RestfulServer.php +++ b/code/RestfulServer.php @@ -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); @@ -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();