8000 merged branch Tobion/patch-3 (PR #5276) · symfony/symfony@71d2301 · GitHub
[go: up one dir, main page]

Skip to content

Commit 71d2301

Browse files
committed
merged branch Tobion/patch-3 (PR #5276)
Commits ------- bdaa877 [HttpFoundation] fix #5271 (duplicated header in JsonResponse) Discussion ---------- fix JsonResponse: duplicate header fix #5271 --------------------------------------------------------------------------- by Tobion at 2012-08-16T16:50:04Z Will look into the failing test later. --------------------------------------------------------------------------- by Tobion at 2012-08-16T23:55:45Z Finished.
2 parents 1996c1f + bdaa877 commit 71d2301

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Symfony/Component/HttpFoundation/JsonResponse.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,16 @@ protected function update()
9797
{
9898
if (null !== $this->callback) {
9999
// Not using application/javascript for compatibility reasons with older browsers.
100-
$this->headers->set('Content-Type', 'text/javascript', true);
100+
$this->headers->set('Content-Type', 'text/javascript');
101101

102102
return $this->setContent(sprintf('%s(%s);', $this->callback, $this->data));
103103
}
104104

105-
$this->headers->set('Content-Type', 'application/json', false);
105+
// Only set the header when there is none or when it equals 'text/javascript' (from a previous update with callback)
106+
// in order to not overwrite a custom definition.
107+
if (!$this->headers->has('Content-Type') || 'text/javascript' === $this->headers->get('Content-Type')) {
108+
$this->headers->set('Content-Type', 'application/json');
109+
}
106110

107111
return $this->setContent($this->data);
108112
}

0 commit comments

Comments
 (0)
0