protected function JsonResponse::update

Updates the content and headers according to the json data and callback.

Return value

JsonResponse

2 calls to JsonResponse::update()
JsonResponse::setCallback in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/JsonResponse.php
Sets the JSONP callback.
JsonResponse::setData in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/JsonResponse.php
Sets the data to be sent as json.

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/JsonResponse.php, line 96

Class

JsonResponse
Response represents an HTTP response in JSON format.

Namespace

Symfony\Component\HttpFoundation

Code

protected function update() {
  if (null !== $this->callback) {

    // Not using application/javascript for compatibility reasons with older browsers.
    $this->headers
      ->set('Content-Type', 'text/javascript');
    return $this
      ->setContent(sprintf('%s(%s);', $this->callback, $this->data));
  }

  // 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);
}