protected static function setContentType($headers, $response)
    {
        if (isset($headers['Content-Type'])) {
            return $headers;
        }
        if (in_array($response->statusCode(), [204, 304])) {
            return $headers;
        }

        $whitelist = [
            'application/javascript', 'application/json', 'application/xml', 'application/rss+xml'
        ];

        $type = $response->type();
        $charset = $response->charset();

        $hasCharset = false;
        if ($charset && (strpos($type, 'text/') === 0 || in_array($type, $whitelist))) {
            $hasCharset = true;
        }

        $value = $type;
        if ($hasCharset) {
            $value = "{$type}; charset={$charset}";
        }
        $headers['Content-Type'] = $value;

        return $headers;
    }