Skip to content

Fixed issue Unable to open URL for downloadable product #19996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 15, 2019
23 changes: 12 additions & 11 deletions app/code/Magento/Downloadable/Helper/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,23 @@ public function getFileSize()
*
* @return string
*/
public function getContentType()
public function getContentType()
{
$this->_getHandle();
if ($this->_linkType == self::LINK_TYPE_FILE) {
if (function_exists(
'mime_content_type'
) && ($contentType = mime_content_type(
$this->_workingDirectory->getAbsolutePath($this->_resourceFile)
))
if ($this->_linkType === self::LINK_TYPE_FILE) {
if (function_exists('mime_content_type')
&& ($contentType = mime_content_type(
$this->_workingDirectory->getAbsolutePath($this->_resourceFile)
))
) {
return $contentType;
} else {
return $this->_downloadableFile->getFileType($this->_resourceFile);
}
} elseif ($this->_linkType == self::LINK_TYPE_URL) {
return $this->_handle->stat($this->_resourceFile)['type'];
return $this->_downloadableFile->getFileType($this->_resourceFile);
}
if ($this->_linkType === self::LINK_TYPE_URL) {
return (is_array($this->_handle->stat($this->_resourceFile)['type'])
? end($this->_handle->stat($this->_resourceFile)['type'])
: $this->_handle->stat($this->_resourceFile)['type']);
}
return $this->_contentType;
}
Expand Down
14 changes: 3 additions & 11 deletions lib/internal/Magento/Framework/Filesystem/Driver/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,18 @@ class Http extends File
*
* @param string $path
* @return bool
* @throws FileSystemException
*/
public function isExists($path)
{
$headers = array_change_key_case(get_headers($this->getScheme() . $path, 1), CASE_LOWER);

$status = $headers[0];

/* Handling 302 redirection */
if (strpos($status, '302 Found') !== false && isset($headers[1])) {
/* Handling 301 or 302 redirection */
if (isset($headers[1]) && preg_match('/30[12]/', $status)) {
$status = $headers[1];
}

if (strpos($status, '200 OK') === false) {
$result = false;
} else {
$result = true;
}

return $result;
return !(strpos($status, '200 OK') === false);
}

/**
Expand Down