/**
  * Set the URI for the next request
  *
  * @param  Microsoft_Uri_Http|string $uri
  * @return Microsoft_Http_Client
  * @throws Microsoft_Http_Client_Exception
  */
 public function setUri($uri)
 {
     if (is_string($uri)) {
         $uri = Microsoft_Uri::factory($uri);
     }
     if (!$uri instanceof Microsoft_Uri_Http) {
         /** @see Microsoft_Http_Client_Exception */
         require_once 'Microsoft/Http/Client/Exception.php';
         throw new Microsoft_Http_Client_Exception('Passed parameter is not a valid HTTP URI.');
     }
     // Set auth if username and password has been specified in the uri
     if ($uri->getUsername() && $uri->getPassword()) {
         $this->setAuth($uri->getUsername(), $uri->getPassword());
     }
     // We have no ports, set the defaults
     if (!$uri->getPort()) {
         $uri->setPort($uri->getScheme() == 'https' ? 443 : 80);
     }
     $this->uri = $uri;
     return $this;
 }
 /**
  * Get a specific cookie according to a URI and name
  *
  * @param Microsoft_Uri_Http|string $uri The uri (domain and path) to match
  * @param string $cookie_name The cookie's name
  * @param int $ret_as Whether to return cookies as objects of Microsoft_Http_Cookie or as strings
  * @return Microsoft_Http_Cookie|string
  */
 public function getCookie($uri, $cookie_name, $ret_as = self::COOKIE_OBJECT)
 {
     if (is_string($uri)) {
         $uri = Microsoft_Uri::factory($uri);
     }
     if (!$uri instanceof Microsoft_Uri_Http) {
         require_once 'Microsoft/Http/Exception.php';
         throw new Microsoft_Http_Exception('Invalid URI specified');
     }
     // Get correct cookie path
     $path = $uri->getPath();
     $path = substr($path, 0, strrpos($path, '/'));
     if (!$path) {
         $path = '/';
     }
     if (isset($this->cookies[$uri->getHost()][$path][$cookie_name])) {
         $cookie = $this->cookies[$uri->getHost()][$path][$cookie_name];
         switch ($ret_as) {
             case self::COOKIE_OBJECT:
                 return $cookie;
                 break;
             case self::COOKIE_STRING_ARRAY:
             case self::COOKIE_STRING_CONCAT:
                 return $cookie->__toString();
                 break;
             default:
                 require_once 'Microsoft/Http/Exception.php';
                 throw new Microsoft_Http_Exception("Invalid value passed for \$ret_as: {$ret_as}");
                 break;
         }
     } else {
         return false;
     }
 }