protected function findContentTypeInHeaders($headers)
    {

        foreach ($headers as $header) {

            $lower = trim(strtolower($header));

            if (strpos($lower, 'content-type:') !== 0) {
                continue;
            }

            $parts = explode(';', $header);

            $keyAndValue = explode(': ', trim($parts[0]), 2);

            if (!isset($keyAndValue[1])) {
                continue;
            }

            return trim($keyAndValue[1]);

        }

        return '';
    }