/** * Downloads a file. * * @param string $url The URL of the file to download. * * @return string The downloaded file body. */ public function download($url) { humbug_set_headers($this->headers); $result = humbug_get_contents($url); if ($result && extension_loaded('zlib')) { $decode = false; foreach (humbug_get_headers() as $header) { if (preg_match('{^content-encoding: *gzip *$}i', $header)) { $decode = true; continue; } elseif (preg_match('{^HTTP/}i', $header)) { $decode = false; } } if ($decode) { $result = version_compare(PHP_VERSION, '5.4.0', '>=') ? zlib_decode($result) : file_get_contents('compress.zlib://data:application/octet-stream;base64,' . base64_encode($result)); if (!$result) { throw new RuntimeException('Failed to decode zlib stream'); } } } return $result; }
public function testCanGetResponseHeaders() { humbug_set_headers(['Accept-Language: da\\r\\n']); humbug_get_contents('http://padraic.github.io'); $this->assertTrue(count(humbug_get_headers()) > 0); }