Add support for alternative download domain #3

Merged
Francesco Siddi merged 4 commits from cdn-support-for-downloads into develop 2024-05-30 09:22:56 +02:00
2 changed files with 4 additions and 11 deletions
Showing only changes of commit a14740af7b - Show all commits

View File

@ -291,10 +291,10 @@ class BuildsRenderer {
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http");
}
// Try to use the CDN host, otherwise use existing host
$host_id = getenv('HOST_CDN') ?: getHostId();
$uri = $protocol . "://$host_id" . "$request_uri";
// Use specific host provided for file downloads if present, otherwise serve
// files from the same domain as the website itself.
$download_host = getenv('DOWNLOAD_FILE_DOMAIN') ?: getHostId();
$uri = $protocol . "://$download_host" . "$request_uri";
$escaped_file_name = htmlspecialchars($build->file_name);

View File

@ -87,13 +87,6 @@ function handleRequest() {
$url = parse_url($_SERVER['REQUEST_URI']);
// Fail requests directed at HOST_CDN if they do not match the /download/*/* pattern
$pattern = "/^\/download\/[^\/]+\/[^\/]+$/";
if (getenv('HOST_CDN') && $_SERVER['HTTP_HOST'] == getenv('HOST_CDN') && !preg_match($pattern, $url['path'])) {
header("HTTP/1.0 404 Not Found");
exit();
}
if ($url['path'] === '/') {
// Root URL
header('Location: /download/daily/');