[HttpFoundation] fix #5271 (duplicated header in JsonResponse)

This commit is contained in:
Tobias Schultze 2012-08-16 19:15:35 +03:00
parent 50df1a72aa
commit bdaa8774af
1 changed files with 6 additions and 2 deletions

View File

@ -97,12 +97,16 @@ class JsonResponse extends Response
{
if (null !== $this->callback) {
// Not using application/javascript for compatibility reasons with older browsers.
$this->headers->set('Content-Type', 'text/javascript', true);
$this->headers->set('Content-Type', 'text/javascript');
return $this->setContent(sprintf('%s(%s);', $this->callback, $this->data));
}
$this->headers->set('Content-Type', 'application/json', false);
// Only set the header when there is none or when it equals 'text/javascript' (from a previous update with callback)
// in order to not overwrite a custom definition.
if (!$this->headers->has('Content-Type') || 'text/javascript' === $this->headers->get('Content-Type')) {
$this->headers->set('Content-Type', 'application/json');
}
return $this->setContent($this->data);
}