public function testCanSetRequestHeaders() { humbug_set_headers(array('Accept-Language: da', 'User-Agent: Humbug')); $out = humbug_get_contents('http://myhttp.info/'); $this->assertEquals(1, preg_match('%' . preg_quote('<td>Accept language</td><td>da</td>') . '%', $out)); $this->assertEquals(1, preg_match('%' . preg_quote('<td>User agent</td><td>Humbug</td>') . '%', $out)); }
/** * 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; }