예제 #1
0
 /**
  * Tests an URL with no userinfo and normalization
  *
  * Also: Regression test for Bug #20385
  *
  * @covers Net_URL2::getUserinfo
  * @covers Net_URL2::normalize
  * @covers Net_URL2::getNormalizedURL
  * @return void
  * @link https://pear.php.net/bugs/bug.php?id=20385
  */
 public function testNoUserinfoAndNormalize()
 {
     $testUrl = 'http://www.example.com/';
     $url = new Net_URL2($testUrl);
     $this->assertFalse($url->getUserinfo());
     $url->normalize();
     $this->assertFalse($url->getUserinfo());
     $this->assertEquals($testUrl, $url->getURL());
     $this->assertEquals($testUrl, $url->getNormalizedURL());
 }
예제 #2
0
 /**
  * Sets the URL for this request
  *
  * If the URL has userinfo part (username & password) these will be removed
  * and converted to auth data. If the URL does not have a path component,
  * that will be set to '/'.
  *
  * @param string|Net_URL2 $url Request URL
  *
  * @return   HTTP_Request2
  * @throws   HTTP_Request2_LogicException
  */
 public function setUrl($url)
 {
     if (is_string($url)) {
         $url = new Net_URL2($url, array(Net_URL2::OPTION_USE_BRACKETS => $this->config['use_brackets']));
     }
     if (!$url instanceof Net_URL2) {
         throw new HTTP_Request2_LogicException('Parameter is not a valid HTTP URL', HTTP_Request2_Exception::INVALID_ARGUMENT);
     }
     // URL contains username / password?
     if ($url->getUserinfo()) {
         $username = $url->getUser();
         $password = $url->getPassword();
         $this->setAuth(rawurldecode($username), $password ? rawurldecode($password) : '');
         $url->setUserinfo('');
     }
     if ('' == $url->getPath()) {
         $url->setPath('/');
     }
     $this->url = $url;
     return $this;
 }
예제 #3
0
 /**
  * Sets the URL for this request
  *
  * If the URL has userinfo part (username & password) these will be removed
  * and converted to auth data. If the URL does not have a path component,
  * that will be set to '/'.
  *
  * @param    string|Net_URL2 Request URL
  * @return   HTTP_Request2
  * @throws   HTTP_Request2_Exception
  */
 public function setUrl($url)
 {
     if (is_string($url)) {
         $url = new Net_URL2($url);
     }
     if (!$url instanceof Net_URL2) {
         throw new HTTP_Request2_Exception('Parameter is not a valid HTTP URL');
     }
     // URL contains username / password?
     if ($url->getUserinfo()) {
         $username = $url->getUser();
         $password = $url->getPassword();
         $this->setAuth(rawurldecode($username), $password ? rawurldecode($password) : '');
         $url->setUserinfo('');
     }
     if ('' == $url->getPath()) {
         $url->setPath('/');
     }
     $this->url = $url;
     return $this;
 }