Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation] reset callback on StreamedResponse when setNotModified() is called #27937

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

Merged
merged 1 commit into from
Jul 13, 2018
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
[HttpFoundation] reset callback on StreamedResponse when setNotModifi…
…ed() is called
  • Loading branch information
rubencm committed Jul 13, 2018
commit 51a49c7f78557a847d512cac6224fc10f6706327
12 changes: 12 additions & 0 deletions 12 src/Symfony/Component/HttpFoundation/StreamedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,16 @@ public function getContent()
{
return false;
}

/**
* {@inheritdoc}
*
* @return $this
*/
public function setNotModified()
{
$this->setCallback(function () {});

return parent::setNotModified();
}
}
7 changes: 6 additions & 1 deletion 7 src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function testMustRevalidateWithProxyRevalidateCacheControlHeader()

public function testSetNotModified()
{
$response = new Response();
$response = new Response('foo');
$modified = $response->setNotModified();
$this->assertObjectHasAttribute('headers', $modified);
$this->assertObjectHasAttribute('content', $modified);
Expand All @@ -135,6 +135,11 @@ public function testSetNotModified()
$this->assertObjectHasAttribute('statusText', $modified);
$this->assertObjectHasAttribute('charset', $modified);
$this->assertEquals(304, $modified->getStatusCode());

ob_start();
$modified->sendContent();
$string = ob_get_clean();
$this->assertEmpty($string);
}

public function testIsSuccessful()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,22 @@ public function testReturnThis()
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
}

public function testSetNotModified()
{
$response = new StreamedResponse(function () { echo 'foo'; });
$modified = $response->setNotModified();
$this->assertObjectHasAttribute('headers', $modified);
$this->assertObjectHasAttribute('content', $modified);
$this->assertObjectHasAttribute('version', $modified);
$this->assertObjectHasAttribute('statusCode', $modified);
$this->assertObjectHasAttribute('statusText', $modified);
$this->assertObjectHasAttribute('charset', $modified);
$this->assertEquals(304, $modified->getStatusCode());

ob_start();
$modified->sendContent();
$string = ob_get_clean();
$this->assertEmpty($string);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.