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());