protected function parseHeaders($headers) { $arHeaders = explode("\n", $headers); foreach ($arHeaders as $k => $header) { if ($k == 0) { if (preg_match('#HTTP\\S+ (\\d+)#', $header, $arFind)) { $this->status = intval($arFind[1]); } } elseif (strpos($header, ':') !== false) { $arHeader = explode(':', $header, 2); if (strtolower($arHeader[0]) == 'set-cookie') { $this->responseCookies->addFromString($arHeader[1]); } $this->responseHeaders->add($arHeader[0], trim($arHeader[1])); } } if (($contentType = $this->responseHeaders->get("Content-Type")) !== null) { $parts = explode(";", $contentType); $this->contentType = trim($parts[0]); foreach ($parts as $part) { $values = explode("=", $part); if (strtolower(trim($values[0])) == "charset") { $this->responseCharset = trim($values[1]); break; } } } }
/** * Returns metadata for downloadable file. * @param string $path Path part of the URL. * @param HttpHeaders $httpHeaders Server's response headers. * @return array|bool Metadata record if mime type and filename were detected, or false otherwise. */ protected static function getFileMetadata($path, HttpHeaders $httpHeaders) { $mimeType = $httpHeaders->getContentType(); $filename = $httpHeaders->getFilename() ?: bx_basename($path); $result = false; if ($mimeType && $filename) { $result = array('TYPE' => UrlMetadataTable::TYPE_FILE, 'EXTRA' => array('ATTACHMENT' => strtolower($httpHeaders->getContentDisposition()) === 'attachment' ? 'Y' : 'N', 'MIME_TYPE' => $mimeType, 'FILENAME' => $filename, 'SIZE' => $httpHeaders->get('Content-Length'))); } return $result; }