3 * Zend Framework (http://framework.zend.com/)
5 * @see http://github.com/zendframework/zend-diactoros for the canonical source repository
6 * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
10 namespace Zend\Diactoros\Response;
12 use function array_keys;
13 use function array_reduce;
14 use function strtolower;
16 trait InjectContentTypeTrait
19 * Inject the provided Content-Type, if none is already present.
21 * @param string $contentType
22 * @param array $headers
23 * @return array Headers with injected Content-Type
25 private function injectContentType($contentType, array $headers)
27 $hasContentType = array_reduce(array_keys($headers), function ($carry, $item) {
28 return $carry ?: (strtolower($item) === 'content-type');
31 if (! $hasContentType) {
32 $headers['content-type'] = [$contentType];