Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable16] Check the actual status code for 204 and 304 #15724

Merged
merged 1 commit into from
May 25, 2019
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
10 changes: 9 additions & 1 deletion lib/private/AppFramework/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,15 @@ public static function main(string $controllerName, string $methodName, DIContai
* 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) {
$emptyResponse = false;
if (preg_match('/^HTTP\/\d\.\d (\d{3}) .*$/', $httpHeaders, $matches)) {
$status = (int)$matches[1];
if ($status === Http::STATUS_NO_CONTENT || $status === Http::STATUS_NOT_MODIFIED) {
$emptyResponse = true;
}
}

if (!$emptyResponse) {
if ($response instanceof ICallbackResponse) {
$response->callback($io);
} else if (!is_null($output)) {
Expand Down
19 changes: 9 additions & 10 deletions tests/lib/AppFramework/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected function setUp() {


public function testControllerNameAndMethodAreBeingPassed(){
$return = array(null, array(), array(), null, new Response());
$return = ['HTTP/2.0 200 OK', [], [], null, new Response()];
$this->dispatcher->expects($this->once())
->method('dispatch')
->with($this->equalTo($this->controller),
Expand Down Expand Up @@ -130,7 +130,7 @@ protected function tearDown() {


public function testOutputIsPrinted(){
$return = [Http::STATUS_OK, [], [], $this->output, new Response()];
$return = ['HTTP/2.0 200 OK', [], [], $this->output, new Response()];
$this->dispatcher->expects($this->once())
->method('dispatch')
->with($this->equalTo($this->controller),
Expand All @@ -144,16 +144,15 @@ public function testOutputIsPrinted(){

public function dataNoOutput() {
return [
[Http::STATUS_NO_CONTENT],
[Http::STATUS_NOT_MODIFIED],
['HTTP/2.0 204 No content'],
['HTTP/2.0 304 Not modified'],
];
}

/**
* @dataProvider dataNoOutput
* @param int $statusCode
*/
public function testNoOutput($statusCode) {
public function testNoOutput(string $statusCode) {
$return = [$statusCode, [], [], $this->output, new Response()];
$this->dispatcher->expects($this->once())
->method('dispatch')
Expand All @@ -173,7 +172,7 @@ public function testCallbackIsCalled(){
$mock = $this->getMockBuilder('OCP\AppFramework\Http\ICallbackResponse')
->getMock();

$return = [null, [], [], $this->output, $mock];
$return = ['HTTP/2.0 200 OK', [], [], $this->output, $mock];
$this->dispatcher->expects($this->once())
->method('dispatch')
->with($this->equalTo($this->controller),
Expand All @@ -188,7 +187,7 @@ public function testCoreApp() {
$this->container['AppName'] = 'core';
$this->container['OC\Core\Controller\Foo'] = $this->controller;

$return = array(null, array(), array(), null, new Response());
$return = ['HTTP/2.0 200 OK', [], [], null, new Response()];
$this->dispatcher->expects($this->once())
->method('dispatch')
->with($this->equalTo($this->controller),
Expand All @@ -205,7 +204,7 @@ public function testSettingsApp() {
$this->container['AppName'] = 'settings';
$this->container['OC\Settings\Controller\Foo'] = $this->controller;

$return = array(null, array(), array(), null, new Response());
$return = ['HTTP/2.0 200 OK', [], [], null, new Response()];
$this->dispatcher->expects($this->once())
->method('dispatch')
->with($this->equalTo($this->controller),
Expand All @@ -222,7 +221,7 @@ public function testApp() {
$this->container['AppName'] = 'bar';
$this->container['OCA\Bar\Controller\Foo'] = $this->controller;

$return = array(null, array(), array(), null, new Response());
$return = ['HTTP/2.0 200 OK', [], [], null, new Response()];
$this->dispatcher->expects($this->once())
->method('dispatch')
->with($this->equalTo($this->controller),
Expand Down