Exemplo n.º 1
0
 public function testExceptAddCookiesInvalidResponse()
 {
     $jar = new Zend_Http_Cookiejar();
     try {
         $jar->addCookiesFromResponse('somestring', 'http://www.example.com');
         $this->fail('Excepted exception was not thrown');
     } catch (Zend_Http_Exception $e) {
         // We are ok
     }
     try {
         $jar->addCookiesFromResponse(new stdClass(), 'http://www.example.com');
         $this->fail('Excepted exception was not thrown');
     } catch (Zend_Http_Exception $e) {
         // We are ok
     }
 }
 /**
  * Test we get an exception in case of invalid response objects
  *
  * @dataProvider invalidResponseProvider
  * @expectedException Zend_Http_Exception
  */
 public function testExceptAddCookiesInvalidResponse($resp)
 {
     $jar = new Zend_Http_Cookiejar();
     $jar->addCookiesFromResponse($resp, 'http://www.example.com');
 }
Exemplo n.º 3
0
 /**
  * Create a new CookieJar object and automatically load into it all the 
  * cookies set in an Http_Response object. If $uri is set, it will be 
  * considered as the requested URI for setting default domain and path
  * of the cookie.
  *
  * @param Zend_Http_Response $response HTTP Response object
  * @param Zend_Uri_Http|string $uri The requested URI 
  * @return Zend_Http_Cookiejar
  * @todo Add the $uri functionality. 
  */
 public static function factory(Zend_Http_Response $response, $ref_uri)
 {
     $jar = new Zend_Http_Cookiejar();
     $jar->addCookiesFromResponse($response, $ref_uri);
     return $jar;
 }
Exemplo n.º 4
0
 /**
  * Prepare the request headers
  * 
  * @return string
  */
 protected function _prepare_headers()
 {
     $headers = "{$this->method} {$this->uri->getPath()}";
     // Get the original GET parameters from the URL
     $query = $this->uri->getQuery();
     // Get the GET parameters that were added using the setParameterGet() method
     if (count($this->paramsGet) > 0) {
         if ($query) {
             $query .= '&';
         }
         // Flatten the GET parameters array
         $params = $this->_getParametersRecursive($this->paramsGet, true);
         foreach ($params as $gp) {
             $query .= "{$gp[0]}={$gp[1]}&";
         }
         $query = substr($query, 0, strlen($query) - 1);
     }
     if ($query) {
         $headers .= "?{$query}";
     }
     $headers .= " HTTP/{$this->http_version}\r\n";
     // Set the host header
     if (!isset($this->headers['host'])) {
         $host = $this->uri->getHost() . ($this->uri->getPort() == 80 ? '' : ':' . $this->uri->getPort());
         $this->setHeader('host', $host);
     }
     // Set the connection header
     // For now, only support closed connections
     if (!isset($this->headers['connection'])) {
         $this->setHeader('connection', 'close');
     }
     // Set the content-type header
     if (!isset($this->headers['content-type']) && isset($this->enctype)) {
         $this->setHeader('content-type', $this->enctype);
     }
     // Set the user agent header
     if (!isset($this->headers['user-agent']) && isset($this->user_agent)) {
         $this->setHeader('user-agent', $this->user_agent);
     }
     // Set HTTP authentication if needed
     if (is_array($this->auth)) {
         $this->setHeader('Authorization', self::encodeAuthHeader($this->auth['user'], $this->auth['password'], $this->auth['type']));
     }
     // Load cookies from cookie jar
     if (isset($this->Cookiejar)) {
         $cookstr = $this->Cookiejar->getMatchingCookies($this->uri, true, Zend_Http_Cookiejar::COOKIE_STRING_CONCAT);
         if ($cookstr) {
             if (isset($this->headers['cookie'])) {
                 $this->headers['cookie'] .= "; {$cookstr}";
             } else {
                 $this->setHeader('cookie', $cookstr);
             }
         }
     }
     // Compile the headers
     foreach ($this->headers as $name => $value) {
         if (is_array($value)) {
             foreach ($value as $subval) {
                 $headers .= ucfirst($name) . ": {$subval}\r\n";
             }
         } else {
             $headers .= ucfirst($name) . ": {$value}\r\n";
         }
     }
     return $headers;
 }