Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions lib/private/AppFramework/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OC\AppFramework\Http\Dispatcher;
use OC_App;
use OC\AppFramework\DependencyInjection\DIContainer;
use OCP\AppFramework\Http;
use OCP\AppFramework\QueryException;
use OCP\AppFramework\Http\ICallbackResponse;

Expand Down Expand Up @@ -142,11 +143,19 @@ public static function main($controllerName, $methodName, DIContainer $container
);
}

if ($response instanceof ICallbackResponse) {
$response->callback($io);
} else if(!is_null($output)) {
$io->setHeader('Content-Length: ' . strlen($output));
$io->setOutput($output);
/*
* Status 204 does not have a body and no Content Length
* Status 304 does not have a body and does not need a Content Length
* https://tools.ietf.org/html/rfc7230#section-3.3
* https://tools.ietf.org/html/rfc7230#section-3.3.2
*/
if ($httpHeaders !== Http::STATUS_NO_CONTENT && $httpHeaders !== Http::STATUS_NOT_MODIFIED) {
if ($response instanceof ICallbackResponse) {
$response->callback($io);
} else if (!is_null($output)) {
$io->setHeader('Content-Length: ' . strlen($output));
$io->setOutput($output);
}
}

}
Expand Down
29 changes: 28 additions & 1 deletion tests/lib/AppFramework/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace Test\AppFramework;

use OC\AppFramework\App;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Response;


Expand Down Expand Up @@ -134,7 +135,7 @@ protected function tearDown() {


public function testOutputIsPrinted(){
$return = [null, [], [], $this->output, new Response()];
$return = [Http::STATUS_OK, [], [], $this->output, new Response()];
$this->dispatcher->expects($this->once())
->method('dispatch')
->with($this->equalTo($this->controller),
Expand All @@ -146,6 +147,32 @@ public function testOutputIsPrinted(){
App::main($this->controllerName, $this->controllerMethod, $this->container, []);
}

public function dataNoOutput() {
return [
[Http::STATUS_NO_CONTENT],
[Http::STATUS_NOT_MODIFIED],
];
}

/**
* @dataProvider dataNoOutput
* @param int $statusCode
*/
public function testNoOutput($statusCode) {
$return = [$statusCode, [], [], $this->output, new Response()];
$this->dispatcher->expects($this->once())
->method('dispatch')
->with($this->equalTo($this->controller),
$this->equalTo($this->controllerMethod))
->will($this->returnValue($return));
$this->io->expects($this->once())
->method('setHeader')
->with($this->equalTo($statusCode));
$this->io->expects($this->never())
->method('setOutput');
App::main($this->controllerName, $this->controllerMethod, $this->container, []);
}


public function testCallbackIsCalled(){
$mock = $this->getMockBuilder('OCP\AppFramework\Http\ICallbackResponse')
Expand Down