From c811a334ba2e8cd5d11176fcad7ced551f969ba3 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 18 Oct 2012 16:41:59 +0200 Subject: [PATCH] Fix IE Download --- .../Phrasea/Controller/Prod/Printer.php | 19 +++++-------------- lib/classes/set/export.class.php | 17 +++++------------ .../Phrasea/Controller/Prod/PrinterTest.php | 7 +++++-- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Printer.php b/lib/Alchemy/Phrasea/Controller/Prod/Printer.php index ebae8c429f..19c277c9c7 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Printer.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Printer.php @@ -57,20 +57,11 @@ class Printer implements ControllerProviderInterface } $PDF = new PDFExport($printer->get_elements(), $layout); - /** - * - * Header "Pragma: public" SHOULD be present. - * In case it is not present, download on IE 8 and previous over HTTPS - * will fail. - * - * @todo : merge this shitty fix with Response object. - * - */ - if ( ! headers_sent()) { - header("Pragma: public"); - } - - return new Response($PDF->render(), 200, array('Content-Type' => 'application/pdf')); + $response = new Response($PDF->render(), 200, array('Content-Type' => 'application/pdf')); + $response->headers->set('Pragma', 'public', true); + $response->setMaxAge(0); + + return $response; } ); diff --git a/lib/classes/set/export.class.php b/lib/classes/set/export.class.php index ed2ab40077..558555073c 100644 --- a/lib/classes/set/export.class.php +++ b/lib/classes/set/export.class.php @@ -792,25 +792,18 @@ class set_export extends set_abstract ); $response->headers->set('X-Sendfile', $file); $response->headers->set('X-Accel-Redirect', $file_xaccel); + $response->headers->set('Pragma', 'public', true); + $response->setMaxAge(0); + $response->headers->set('Content-Type', $mime); $response->headers->set('Content-Length', filesize($file)); $response->headers->set('Content-Disposition', $headerDisposition); return $response; } else { - /** - * - * Header "Pragma: public" SHOULD be present. - * In case it is not present, download on IE 8 and previous over HTTPS - * will fail. - * - * @todo : merge this shitty fix with Response object. - * - */ - if ( ! headers_sent()) { - header("Pragma: public"); - } + $response->headers->set('Pragma', 'public', true); + $response->setMaxAge(0); $response->headers->set('Content-Type', $mime); $response->headers->set('Content-Length', filesize($file)); diff --git a/tests/Alchemy/Phrasea/Controller/Prod/PrinterTest.php b/tests/Alchemy/Phrasea/Controller/Prod/PrinterTest.php index f99732f93e..de70a63d69 100644 --- a/tests/Alchemy/Phrasea/Controller/Prod/PrinterTest.php +++ b/tests/Alchemy/Phrasea/Controller/Prod/PrinterTest.php @@ -9,10 +9,10 @@ class ControllerPrinterTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function createApplication() { $app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php'; - + $app['debug'] = true; unset($app['exception_handler']); - + return $app; } @@ -72,6 +72,9 @@ class ControllerPrinterTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertEquals("application/pdf", $response->headers->get("content-type")); $this->assertTrue($response->isOk()); + $this->assertEquals(0, $response->getMaxAge()); + $this->assertTrue($response->headers->has('pragma')); + $this->assertEquals('public', $response->headers->get('pragma')); } } }