Skip to content

Commit 07b279c

Browse files
committed
bug symfony#54506 [HttpFoundation] Set content-type header in RedirectResponse (smnandre)
This PR was submitted for the 7.1 branch but it was squashed and merged into the 5.4 branch instead. Discussion ---------- [HttpFoundation] Set content-type header in RedirectResponse | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | Fix symfony#54434 | License | MIT The RedirectResponse has no content-type set, leading to the response using the "current" one (see issue symfony#54434) As `setTargetUrl` set response body with HTML/UTF-8 content, it seems fair to add the matching header at this moment. (not sure if really a _bug_ or not so i'm targetting 7.1 for now) Commits ------- 954f1af [HttpFoundation] Set content-type header in RedirectResponse
2 parents 2377fc7 + 954f1af commit 07b279c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Symfony/Component/HttpFoundation/RedirectResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public function setTargetUrl(string $url)
103103
</html>', htmlspecialchars($url, \ENT_QUOTES, 'UTF-8')));
104104

105105
$this->headers->set('Location', $url);
106+
$this->headers->set('Content-Type', 'text/html; charset=utf-8');
106107

107108
return $this;
108109
}

src/Symfony/Component/HttpFoundation/Tests/RedirectResponseTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public function testGenerateLocationHeader()
4444
$this->assertEquals('foo.bar', $response->headers->get('Location'));
4545
}
4646

47+
public function testGenerateContentTypeHeader()
48+
{
49+
$response = new RedirectResponse('foo.bar');
50+
51+
$this->assertSame('text/html; charset=utf-8', $response->headers->get('Content-Type'));
52+
}
53+
4754
public function testGetTargetUrl()
4855
{
4956
$response = new RedirectResponse('foo.bar');

0 commit comments

Comments
 (0)