Merge pull request #1300 from nextcloud/fix_ocs_content_type
Set proper content type on OCS responses
This commit is contained in:
commit
c8ec237cbe
3 changed files with 42 additions and 0 deletions
|
@ -201,6 +201,14 @@ trait BasicStructure {
|
|||
PHPUnit_Framework_Assert::assertEquals($statusCode, $this->response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the Content-Type should be "([^"]*)"$/
|
||||
* @param string $contentType
|
||||
*/
|
||||
public function theContentTypeShouldbe($contentType) {
|
||||
PHPUnit_Framework_Assert::assertEquals($contentType, $this->response->getHeader('Content-Type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
|
|
24
build/integration/features/ocs-v1.feature
Normal file
24
build/integration/features/ocs-v1.feature
Normal file
|
@ -0,0 +1,24 @@
|
|||
Feature: ocs
|
||||
Background:
|
||||
Given using api version "1"
|
||||
|
||||
Scenario: Default output is xml
|
||||
Given user "user0" exists
|
||||
And As an "user0"
|
||||
When sending "GET" to "/cloud/config"
|
||||
And the HTTP status code should be "200"
|
||||
And the Content-Type should be "text/xml; charset=UTF-8"
|
||||
|
||||
Scenario: Get XML when requesting XML
|
||||
Given user "user0" exists
|
||||
And As an "user0"
|
||||
When sending "GET" to "/cloud/config?format=xml"
|
||||
And the HTTP status code should be "200"
|
||||
And the Content-Type should be "text/xml; charset=UTF-8"
|
||||
|
||||
Scenario: Get JSON when requesting JSON
|
||||
Given user "user0" exists
|
||||
And As an "user0"
|
||||
When sending "GET" to "/cloud/config?format=json"
|
||||
And the HTTP status code should be "200"
|
||||
And the Content-Type should be "application/json; charset=utf-8"
|
|
@ -68,6 +68,16 @@ abstract class BaseResponse extends Response {
|
|||
$this->setLastModified($dataResponse->getLastModified());
|
||||
$this->setCookies($dataResponse->getCookies());
|
||||
$this->setContentSecurityPolicy($dataResponse->getContentSecurityPolicy());
|
||||
|
||||
if ($format === 'json') {
|
||||
$this->addHeader(
|
||||
'Content-Type', 'application/json; charset=utf-8'
|
||||
);
|
||||
} else {
|
||||
$this->addHeader(
|
||||
'Content-Type', 'application/xml; charset=utf-8'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue