From 4a6ef31b1a265269f322621ea98d61b05bb89749 Mon Sep 17 00:00:00 2001 From: Sebastiaan Stok Date: Mon, 3 Sep 2012 15:43:53 +0200 Subject: [PATCH] fixed wrong detection of file-type and use proper headers for binary files --- src/GitList/Controller/BlobController.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/GitList/Controller/BlobController.php b/src/GitList/Controller/BlobController.php index 9c710c2..06c445b 100644 --- a/src/GitList/Controller/BlobController.php +++ b/src/GitList/Controller/BlobController.php @@ -19,7 +19,7 @@ class BlobController implements ControllerProviderInterface $breadcrumbs = $app['util.view']->getBreadcrumbs($file); $fileType = $app['util.repository']->getFileType($file); - if ($fileType !== 'image' && $app['util.repository']->isBinary($fileType)) { + if ($fileType !== 'image' && $app['util.repository']->isBinary($file)) { return $app->redirect($app['url_generator']->generate('blob_raw', array( 'repo' => $repo, 'branch' => $branch, @@ -46,7 +46,17 @@ class BlobController implements ControllerProviderInterface $repository = $app['git']->getRepository($app['git.repos'] . $repo); $blob = $repository->getBlob("$branch:\"$file\"")->output(); - return new Response($blob, 200, array('Content-Type' => 'text/plain')); + $headers = array(); + + if ($app['util.repository']->isBinary($file)) { + $headers['Content-Disposition'] = 'attachment; filename="' . $file . '"'; + $headers['Content-Transfer-Encoding'] = 'application/octet-stream'; + $headers['Content-Transfer-Encoding'] = 'binary'; + } else { + $headers['Content-Transfer-Encoding'] = 'text/plain'; + } + + return new Response($blob, 200, $headers); })->assert('file', '.+') ->assert('repo', '[\w-._]+') ->assert('branch', '[\w-._]+')