From bb1ef65011a14730b7cfbe73506b4bb8a03704bd Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Tue, 29 Mar 2022 17:28:03 -0400 Subject: [PATCH] Add a default context - creates a user agent - disables following redirects --- src/Options.php | 12 ++++++++++++ tests/DompdfTest.php | 1 - 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Options.php b/src/Options.php index 478503f3a..69c43bd9d 100644 --- a/src/Options.php +++ b/src/Options.php @@ -298,6 +298,18 @@ public function __construct(array $attributes = null) $this->setFontDir($rootDir . "/lib/fonts"); $this->setFontCache($this->getFontDir()); + $ver = ""; + $versionFile = realpath(__DIR__ . "/../VERSION"); + if (file_exists($versionFile) && ($version = trim(file_get_contents($versionFile))) !== false && $version !== '$Format:<%h>$') { + $ver = "/$version"; + } + $this->setHttpContext([ + "http" => [ + "follow_location" => false, + "user_agent" => "Dompdf$ver https://github.com/dompdf/dompdf" + ] + ]); + if (null !== $attributes) { $this->set($attributes); } diff --git a/tests/DompdfTest.php b/tests/DompdfTest.php index b53da9664..dcd763e9c 100644 --- a/tests/DompdfTest.php +++ b/tests/DompdfTest.php @@ -21,7 +21,6 @@ public function testConstructor() $this->assertIsArray($dompdf->getCallbacks()); $this->assertInstanceOf(Stylesheet::class, $dompdf->getCss()); $this->assertNull($dompdf->getDom()); - $this->assertNull($dompdf->getHttpContext()); $this->assertInstanceOf(Options::class, $dompdf->getOptions()); $this->assertFalse($dompdf->getQuirksmode()); $this->assertNull($dompdf->getTree());