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

Commit 51a49c7

Browse filesBrowse files
committed
[HttpFoundation] reset callback on StreamedResponse when setNotModified() is called
1 parent 3b90bc7 commit 51a49c7
Copy full SHA for 51a49c7

File tree

3 files changed

+36
-1
lines changed
Filter options

3 files changed

+36
-1
lines changed

‎src/Symfony/Component/HttpFoundation/StreamedResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/StreamedResponse.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,16 @@ public function getContent()
134134
{
135135
return false;
136136
}
137+
138+
/**
139+
* {@inheritdoc}
140+
*
141+
* @return $this
142+
*/
143+
public function setNotModified()
144+
{
145+
$this->setCallback(function () {});
146+
147+
return parent::setNotModified();
148+
}
137149
}

‎src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testMustRevalidateWithProxyRevalidateCacheControlHeader()
126126

127127
public function testSetNotModified()
128128
{
129-
$response = new Response();
129+
$response = new Response('foo');
130130
$modified = $response->setNotModified();
131131
$this->assertObjectHasAttribute('headers', $modified);
132132
$this->assertObjectHasAttribute('content', $modified);
@@ -135,6 +135,11 @@ public function testSetNotModified()
135135
$this->assertObjectHasAttribute('statusText', $modified);
136136
$this->assertObjectHasAttribute('charset', $modified);
137137
$this->assertEquals(304, $modified->getStatusCode());
138+
139+
ob_start();
140+
$modified->sendContent();
141+
$string = ob_get_clean();
142+
$this->assertEmpty($string);
138143
}
139144

140145
public function testIsSuccessful()

‎src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,22 @@ public function testReturnThis()
132132
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
133133
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
134134
}
135+
136+
public function testSetNotModified()
137+
{
138+
$response = new StreamedResponse(function () { echo 'foo'; });
139+
$modified = $response->setNotModified();
140+
$this->assertObjectHasAttribute('headers', $modified);
141+
$this->assertObjectHasAttribute('content', $modified);
142+
$this->assertObjectHasAttribute('version', $modified);
143+
$this->assertObjectHasAttribute('statusCode', $modified);
144+
$this->assertObjectHasAttribute('statusText', $modified);
145+
$this->assertObjectHasAttribute('charset', $modified);
146+
$this->assertEquals(304, $modified->getStatusCode());
147+
148+
ob_start();
149+
$modified->sendContent();
150+
$string = ob_get_clean();
151+
$this->assertEmpty($string);
152+
}
135153
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.