mirror of
https://github.com/silverstripe/silverstripe-restfulserver
synced 2024-10-22 14:05:58 +02:00
FIX Return string directly when no body content is provided to put/post methods
This commit is contained in:
parent
4ba5bf5853
commit
b3fc6803fd
@ -405,7 +405,11 @@ class RestfulServer extends Controller
|
||||
return $this->unsupportedMediaType();
|
||||
}
|
||||
|
||||
/** @var DataObject|string */
|
||||
$obj = $this->updateDataObject($obj, $reqFormatter);
|
||||
if (is_string($obj)) {
|
||||
return $obj;
|
||||
}
|
||||
|
||||
$this->getResponse()->setStatusCode(200); // Success
|
||||
$this->getResponse()->addHeader('Content-Type', $responseFormatter->getOutputContentType());
|
||||
@ -470,7 +474,11 @@ class RestfulServer extends Controller
|
||||
|
||||
$responseFormatter = $this->getResponseDataFormatter($className);
|
||||
|
||||
/** @var DataObject|string $obj */
|
||||
$obj = $this->updateDataObject($obj, $reqFormatter);
|
||||
if (is_string($obj)) {
|
||||
return $obj;
|
||||
}
|
||||
|
||||
$this->getResponse()->setStatusCode(201); // Created
|
||||
$this->getResponse()->addHeader('Content-Type', $responseFormatter->getOutputContentType());
|
||||
@ -498,7 +506,7 @@ class RestfulServer extends Controller
|
||||
*
|
||||
* @param DataObject $obj
|
||||
* @param DataFormatter $formatter
|
||||
* @return DataObject The passed object
|
||||
* @return DataObject|string The passed object, or "No Content" if incomplete input data is provided
|
||||
*/
|
||||
protected function updateDataObject($obj, $formatter)
|
||||
{
|
||||
|
@ -193,6 +193,19 @@ class RestfulServerTest extends SapphireTest
|
||||
unset($_SERVER['PHP_AUTH_PW']);
|
||||
}
|
||||
|
||||
public function testPostWithoutBodyReturnsNoContent()
|
||||
{
|
||||
$_SERVER['PHP_AUTH_USER'] = 'editor@test.com';
|
||||
$_SERVER['PHP_AUTH_PW'] = 'editor';
|
||||
|
||||
$url = '/api/v1/RestfulServerTest_Comment';
|
||||
$response = Director::test($url, null, null, 'POST');
|
||||
|
||||
$this->assertEquals('No Content', $response->getBody());
|
||||
|
||||
unset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
|
||||
}
|
||||
|
||||
public function testPUTwithJSON()
|
||||
{
|
||||
$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
|
||||
|
Loading…
Reference in New Issue
Block a user