organic: Fix Content-Disposition
This commit is contained in:
4
www/organic/external/easy-cert/operators.php
vendored
4
www/organic/external/easy-cert/operators.php
vendored
@@ -267,9 +267,7 @@ $process = proc_open(
|
|||||||
$pipes
|
$pipes
|
||||||
);
|
);
|
||||||
fclose($pipes[0]);
|
fclose($pipes[0]);
|
||||||
while (($line = fgets($pipes[1])) !== false) {
|
fpassthru($pipes[1]);
|
||||||
echo $line;
|
|
||||||
}
|
|
||||||
fclose($pipes[1]);
|
fclose($pipes[1]);
|
||||||
$stderr = stream_get_contents($pipes[2]);
|
$stderr = stream_get_contents($pipes[2]);
|
||||||
fclose($pipes[2]);
|
fclose($pipes[2]);
|
||||||
|
@@ -176,7 +176,54 @@ if ($format === 'text') {
|
|||||||
echo "{\"type\":\"unknown\"}\n";
|
echo "{\"type\":\"unknown\"}\n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$fd_spec = [
|
||||||
|
0 => ["pipe", "r"], // stdin
|
||||||
|
1 => ["pipe", "w"], // stdout
|
||||||
|
2 => ["pipe", "w"], // stderr
|
||||||
|
3 => ["pipe", "w"], // headers
|
||||||
|
];
|
||||||
|
$process = proc_open(['curl', '-s', '-D', '/dev/fd/3', $url], $fd_spec, $pipes);
|
||||||
|
fclose($pipes[0]);
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$status_code = null;
|
||||||
|
while (($line = fgets($pipes[3])) !== false) {
|
||||||
|
if (trim($line) === '') break;
|
||||||
|
if ($status_code === null) {
|
||||||
|
$status_code = intval(explode(' ', $line)[1]);
|
||||||
|
if ($status_code !== 200)
|
||||||
|
break;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
[$k,$v] = explode(':', $line, 2);
|
||||||
|
$k = strtolower(trim($k));
|
||||||
|
$v = trim($v);
|
||||||
|
$headers[$k] = $v;
|
||||||
|
}
|
||||||
|
fclose($pipes[3]);
|
||||||
|
|
||||||
|
if ($status_code === 200 && str_starts_with($headers['content-type'], "application/pdf")) {
|
||||||
header('Content-Type: application/pdf');
|
header('Content-Type: application/pdf');
|
||||||
$s = curl_init($url);
|
$content_length = null;
|
||||||
curl_exec($s);
|
if (isset($headers['content-length'])) {
|
||||||
|
$content_length = intval($headers['content-length']);
|
||||||
|
header('Content-Length: ' . $headers['content-length']);
|
||||||
|
}
|
||||||
|
$parts = explode('/', $url);
|
||||||
|
$filename = $parts[sizeof($parts) - 1];
|
||||||
|
if (isset($headers['content-disposition'])) {
|
||||||
|
preg_match('@filename="(.*?)"@', $headers['content-disposition'], $matches);
|
||||||
|
$filename = $matches[1];
|
||||||
|
}
|
||||||
|
header('Content-Disposition: inline; filename="' . $filename . '"');
|
||||||
|
fpassthru($pipes[1]);
|
||||||
|
} else {
|
||||||
|
header('Status: 500');
|
||||||
|
header('Content-Length: 0');
|
||||||
|
}
|
||||||
|
fclose($pipes[1]);
|
||||||
|
|
||||||
|
$stderr = stream_get_contents($pipes[2]);
|
||||||
|
fclose($pipes[2]);
|
||||||
|
$return_value = proc_close($process);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user