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)); }
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)); }
/** * 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; }
/** * 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; }
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)); }
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); }
/** * @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; }
/** * 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()); }