本文整理汇总了PHP中Zend_Http_Response::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Response::getHeaders方法的具体用法?PHP Zend_Http_Response::getHeaders怎么用?PHP Zend_Http_Response::getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_Response
的用法示例。
在下文中一共展示了Zend_Http_Response::getHeaders方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testClearHeaders
public function testClearHeaders()
{
$this->_response->setHeader('Content-Type', 'text/xml');
$headers = $this->_response->getHeaders();
$this->assertEquals(1, count($headers));
$this->_response->clearHeaders();
$headers = $this->_response->getHeaders();
$this->assertEquals(0, count($headers));
}
示例2: testClearAllHeaders
public function testClearAllHeaders()
{
$this->_response->setRawHeader('HTTP/1.0 404 Not Found');
$this->_response->setHeader('Content-Type', 'text/xml');
$headers = $this->_response->getHeaders();
$this->assertFalse(empty($headers));
$headers = $this->_response->getRawHeaders();
$this->assertFalse(empty($headers));
$this->_response->clearAllHeaders();
$headers = $this->_response->getHeaders();
$this->assertTrue(empty($headers));
$headers = $this->_response->getRawHeaders();
$this->assertTrue(empty($headers));
}
示例3: sendRequest
/**
* Sends a request and returns a response
*
* @param CartRecover_Request $request
* @return Cart_Recover_Response
*/
public function sendRequest(CartRecover_Request $request)
{
$url = Guzzle\Http\Url::factory($request->getUri());
$url->setQuery($request->getParams());
$this->client->setBaseUrl($url);
$grequest = $this->client->createRequest($request->getMethod(), $url);
$grequest->addHeader('Accept', 'application/json');
$this->response = $this->client->send($grequest);
if (!$this->response->isContentType('application/json')) {
throw new CartRecover_Exception_UnexpectedValueException("Unknown response format.");
}
$response = new CartRecover_Response();
$response->setRawResponse($this->response->__toString());
$response->setBody($this->response->json());
$response->setHeaders($this->response->getHeaders()->toArray());
$response->setStatus($this->response->getReasonPhrase(), $this->response->getStatusCode());
return $response;
}
示例4: sendRequest
/**
* Sends a request and returns a response
*
* @param CartRecover_Request $request
* @return Cart_Recover_Response
*/
public function sendRequest(CartRecover_Request $request)
{
$this->client->setUri($request->getUri());
$this->client->setParameterGet($request->getParams());
$this->client->setMethod($request->getMethod());
$this->client->setHeaders('Accept', 'application/json');
$this->response = $this->client->request();
if ($this->response->getHeader('Content-Type') != 'application/json') {
throw new CartRecover_Exception_UnexpectedValueException("Unknown response format.");
}
$body = json_decode($this->response->getBody(), true);
$response = new CartRecover_Response();
$response->setRawResponse($this->response->asString());
$response->setBody($body);
$response->setHeaders($this->response->getHeaders());
$response->setStatus($this->response->getMessage(), $this->response->getStatus());
return $response;
}
示例5: testHeaderNamesAreCaseInsensitive
public function testHeaderNamesAreCaseInsensitive()
{
$this->_response->setHeader('X-Foo_Bar-Baz', 'value');
$this->_response->setHeader('X-FOO_bar-bAz', 'bat');
$headers = $this->_response->getHeaders();
$names = array();
foreach ($headers as $header) {
$names[] = $header['name'];
}
$this->assertTrue(in_array('X-Foo-Bar-Baz', $names), var_export($headers, 1));
$this->assertFalse(in_array('X-Foo_Bar-Baz', $names));
$this->assertFalse(in_array('X-FOO_bar-bAz', $names));
}
示例6: createResponse
protected function createResponse(\Zend_Http_Response $response)
{
$headers = array($response->getHeader('Set-Cookie'));
$cookies = array();
foreach ($headers as $header) {
if (!trim($header)) {
continue;
}
$parts = explode(';', $header);
$value = array_shift($parts);
list($name, $value) = explode('=', trim($value));
$cookies[$name] = array('value' => $value);
foreach ($parts as $part) {
list($key, $value) = explode('=', trim($part));
$cookies[$name][$key] = $value;
}
}
return new Response($response->getBody(), $response->getStatus(), $response->getHeaders(), $cookies);
}
示例7: parse
/**
* @param string $link
* @param Zend_Http_Response $response
* @param string $host
* @param Zend_Http_CookieJar $cookieJar
* @param integer $depth
* @return boolean
*/
protected function parse($link, $response, $host, $cookieJar, $depth)
{
$success = false;
if (strpos($link, "https://") !== FALSE) {
$protocol = "https";
} else {
if (strpos($link, "http://") !== FALSE) {
$protocol = "http";
} else {
logger::log(get_class($this) . " parsing [{$link}] not possible. Only parsing http and https ", Zend_Log::DEBUG);
return;
}
}
$headers = $response->getHeaders();
if (array_key_exists("Content-Type", $headers)) {
$contentType = $response->getHeader("Content-Type");
} else {
if (array_key_exists("Content-type", $headers)) {
$contentType = $response->getHeader("Content-Type");
} else {
if (array_key_exists("content-type", $headers)) {
$contentType = $response->getHeader("Content-Type");
} else {
if (array_key_exists("content-Type", $headers)) {
$contentType = $response->getHeader("Content-Type");
}
}
}
}
if (!empty($contentType)) {
$parts = explode(";", $contentType);
$mimeType = trim($parts[0]);
if ($mimeType == "text/html") {
$success = $this->parseHtml($link, $response, $host, $protocol, $cookieJar, $depth);
} else {
if ($mimeType == "application/pdf") {
$success = $this->parsePdf($link, $response);
} else {
logger::log(get_class($this) . " Cannot parse mime type [ {$mimeType} ] provided by link [ {$link} ] " . Zend_Log::ERR);
}
}
} else {
logger::log(get_class($this) . " Could not determine content type of [ {$link} ] " . Zend_Log::ERR);
}
return $success;
}
示例8: initializeResponse
/**
* Initializes response object.
*
* @param Zend_Http_Response $response
*
* @return Jirafe_HttpConnection_Response
*/
protected function initializeResponse(Zend_Http_Response $response)
{
return new Jirafe_HttpConnection_Response($response->getBody(), $response->getHeaders(), $response->isError() ? $response->getStatus() : 0, $response->getMessage());
}