/** * This method enables logging of requests by changing the * Zend_Http_Client_Adapter used for performing the requests. * NOTE: This will not work if you have customized the adapter * already to use a proxy server or other interface. * * @param $logfile The logfile to use when logging the requests */ public function enableRequestDebugLogging($logfile) { $this->_httpClient->setConfig(array( 'adapter' => 'Zend\GData\App\LoggingHttpClientAdapterSocket', 'logfile' => $logfile )); }
/** * Test sending cookie header with raw value * * @group fix-double-encoding-problem-about-cookie-value */ public function testRawCookiesInRequestHeaders() { $this->_client->setConfig(array('encodecookies' => false)); $this->_client->addCookie('foo', 'bar=baz'); $this->_client->send(); $cookieValue = 'Cookie: foo=bar=baz'; $this->assertContains($cookieValue, $this->_client->getLastRawRequest(), 'Request is expected to contain the entire cookie "keyname=raw_value"'); }
/** * * @return void */ public function setUp() { if (!constant('TESTS_ZEND_SERVICE_DELICIOUS_ENABLED')) { $this->markTestSkipped('\\Zend\\Service\\Delicious online tests are not enabled'); } $httpClient = new Http\Client(); $httpClient->setConfig(array('useragent' => 'Zend\\Service\\Delicious - Unit tests/0.1', 'keepalive' => true)); RestClient\RestClient::setDefaultHttpClient($httpClient); $this->_delicious = new Delicious\Delicious(self::TEST_UNAME, self::TEST_PASS); }
/** * Check we get an exception if there's an error in the socket * */ public function testSocketErrorException() { $this->setExpectedException('Zend\\Http\\Client\\Adapter\\Exception\\RuntimeException', 'Unable to Connect to tcp://255.255.255.255:80'); // Try to connect to an invalid host $this->_client->setUri('http://255.255.255.255'); // Reduce timeout to 3 seconds to avoid waiting $this->_client->setConfig(array('timeout' => 3)); // This call should cause an exception $this->_client->send(); }
/** * Test we can properly redirect to a relative path * */ public function testRelativePathRedirect() { $this->client->setUri($this->baseuri . 'testRelativeRedirections.php'); $this->client->setParameterGet(array('redirect' => 'relpath')); $this->client->setConfig(array('maxredirects' => 1)); // Set the new expected URI $uri = clone $this->client->getUri(); $uri->setPath(rtrim(dirname($uri->getPath()), '/') . '/path/to/fake/file.ext'); $uri = $uri->__toString(); $res = $this->client->send(); $this->assertEquals("{$uri}?redirect=relpath", $this->client->getUri()->toString(), "The new location is not as expected: {$this->client->getUri()->toString()}"); }
/** * Returns the instance of the Zend\Http\Client which will be used. Creates an instance * of Zend\Http\Client if no previous client was set. * * @return Zend\Http\Client The HTTP client which will be used */ public function getHttpClient() { if (!$this->httpclient instanceof Http\Client) { $client = new Http\Client(); $client->setConfig(array('maxredirects' => 2, 'timeout' => 5)); $this->setHttpClient($client); } $this->httpclient->resetParameters(); return $this->httpclient; }
/** * Fetch item and holding records from an ILS for this record */ public function fetchHoldings() { $xerxes_record = $this->getXerxesRecord(); $id = $xerxes_record->getRecordID(); // id from the record $cache_id = $xerxes_record->getSource() . "." . $id; // to identify this in the cache $url = $this->config->getConfig("LOOKUP"); // url to availability server // mark that we've checked holdings either way $this->holdings->checked = true; // no holdings source defined or somehow id's are blank if ($xerxes_record->hasPhysicalHoldings() == false || $url == "" || $id == "") { return null; } // get the data $url .= "?action=status&id=" . urlencode($id); // @todo this needs to be gotten from a factory or something $client = new Client(); $client->setUri($url); $client->setConfig(array('timeout' => 5)); $data = $client->send()->getBody(); // echo $url; exit; // no data, what's up with that? if ($data == "") { throw new \Exception("could not connect to availability server"); } // response is (currently) an array of json objects $results = json_decode($data); // parse the response if (is_array($results)) { if (count($results) > 0) { // now just slot them into our item object foreach ($results as $holding) { $is_holding = property_exists($holding, "holding"); if ($is_holding == true) { $item = new Holding(); $this->holdings->addHolding($item); } else { $item = new Item(); $this->holdings->addItem($item); } foreach ($holding as $property => $value) { $item->setProperty($property, $value); } } } } // cache it for the future // @todo: zend\cache $cache = new Cache(); $expiry = $this->config->getConfig("HOLDINGS_CACHE_EXPIRY", false, 2 * 60 * 60); // expiry set for two hours $expiry += time(); $cache->set($cache_id, serialize($this->holdings), $expiry); return null; }