Skip to content
Snippets Groups Projects

Resolve "Fix Downloading of files"

Merged Dominik Hebeler requested to merge 20-fix-downloading-of-files into master
3 files
+ 33
0
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -197,6 +197,37 @@ class ProxyController extends Controller
$httpcode = $answer["http-code"];
extract(parse_url($targetUrl));
$base = $scheme . "://" . $host;
$headerArray = [];
foreach ($answer["headers"] as $index => $value) {
if (strtolower($index) === "location") {
$redLink = $value;
if (strpos($redLink, "/") === 0) {
$parse = parse_url($url);
$redLink = $parse["scheme"] . "://" . $parse["host"] . $redLink;
} elseif (preg_match("/^\w+\.\w+$/si", $redLink)) {
$parse = parse_url($url);
$redLink = $parse["scheme"] . "://" . $parse["host"] . "/" . $redLink;
}
$key = md5($request->ip() . microtime(true));
$headerArray[trim($index)] = $this->proxifyUrl($redLink, null, $key, false);
} elseif (strtolower($index) === "content-disposition") {
$headerArray[strtolower(trim($index))] = strtolower(trim($value));
} else {
$headerArray[trim($index)] = trim($value);
}
}
$answer["headers"] = $headerArray;
# It might happen that a server doesn't give Information about file Type.
# Let's try to generate one in this case
if (!isset($answer["headers"]["content-type"])) {
$finfo = new finfo(FILEINFO_MIME);
$answer["headers"]["content-type"] = $finfo->buffer(base64_decode($answer["body"]));
}
# We will parse whether we have a parser for this document type.
# If not, we will not Proxy it:
$contentTypeHeader = $answer["headers"]["content-type"];
Loading