You are here

protected function BlueprintManager::negotiateSubContentType in Subrequests 8.2

Same name and namespace in other branches
  1. 3.x src/Blueprint/BlueprintManager.php \Drupal\subrequests\Blueprint\BlueprintManager::negotiateSubContentType()

Negotiates the sub Content-Type.

Checks if all responses have the same Content-Type header. If they do, then it returns that one. If not, it defaults to 'application/json'.

Parameters

\Symfony\Component\HttpFoundation\Response[] $responses: The responses.

Return value

string The collective content type. 'application/json' if no conciliation is possible.

1 call to BlueprintManager::negotiateSubContentType()
BlueprintManager::combineResponses in src/Blueprint/BlueprintManager.php

File

src/Blueprint/BlueprintManager.php, line 83

Class

BlueprintManager

Namespace

Drupal\subrequests\Blueprint

Code

protected function negotiateSubContentType($responses) {
  $output = array_reduce($responses, function ($carry, Response $response) {
    $ct = $response->headers
      ->get('Content-Type');
    if (!isset($carry)) {
      $carry = $ct;
    }
    if ($carry !== $ct) {
      $carry = 'application/json';
    }
    return $carry;
  });
  return $output ?: 'application/json';
}