예제 #1
0
 /**
  * Returns all cookies matching a given request URL
  *
  * The following checks are made:
  *   - cookie domain should match request host
  *   - cookie path should be a prefix for request path
  *   - 'secure' cookies will only be sent for HTTPS requests
  *
  * @param Net_URL2 $url      Request url
  * @param bool     $asString Whether to return cookies as string for "Cookie: " header
  *
  * @return array|string Matching cookies
  */
 public function getMatching(Net_URL2 $url, $asString = false)
 {
     $host = $url->getHost();
     $path = $url->getPath();
     $secure = 0 == strcasecmp($url->getScheme(), 'https');
     $matched = $ret = array();
     foreach (array_keys($this->cookies) as $domain) {
         if ($this->domainMatch($host, $domain)) {
             foreach (array_keys($this->cookies[$domain]) as $cPath) {
                 if (0 === strpos($path, $cPath)) {
                     foreach ($this->cookies[$domain][$cPath] as $name => $cookie) {
                         if (!$cookie['secure'] || $secure) {
                             $matched[$name][strlen($cookie['path'])] = $cookie;
                         }
                     }
                 }
             }
         }
     }
     foreach ($matched as $cookies) {
         krsort($cookies);
         $ret = array_merge($ret, $cookies);
     }
     if (!$asString) {
         return $ret;
     } else {
         $str = '';
         foreach ($ret as $c) {
             $str .= (empty($str) ? '' : '; ') . $c['name'] . '=' . $c['value'];
         }
         return $str;
     }
 }
예제 #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;
 }
 /**
  * Checks whether the requested URI is the authentication URI or not.
  *
  * @param string $authenticationURI
  * @return boolean
  */
 private function _isAuthenticationURI($authenticationURI)
 {
     $url = new Net_URL2($authenticationURI);
     return $this->context->removeProxyPath($url->getPath()) == $this->_scriptName;
 }
예제 #4
0
파일: edit.php 프로젝트: stof/pearweb
$project_label = $form->addElement("text", "project_label", array('required' => 'required', 'placeholder' => 'PHPUnit'));
$project_label->setLabel("Project Name");
$project_label->addFilter("htmlspecialchars");
$project_label->addRule('required', "Please enter your project name");
$project_link = $form->addElement("url", "project_link", array('required' => 'required', 'placeholder' => 'http://phpunit.de/'));
$project_link->setLabel("Project Homepage");
$project_link->addFilter("htmlspecialchars");
$project_link->addRule('required', "Please enter your project link");
$is_active = $form->addElement("checkbox", 'is_active', array('checked' => $channel["is_active"] ? 'checked' : ''));
$is_active->setLabel("Active?");
$form->addElement("submit");
if ($form->validate()) {
    $url = new Net_URL2($project_name->getValue());
    try {
        $req = new HTTP_Request2();
        $dir = explode("/", $url->getPath());
        if (!empty($dir)) {
            array_pop($dir);
        }
        $dir[] = 'channel.xml';
        $url->setPath(implode("/", $dir));
        $req->setURL($url->getURL());
        channel::validate($req, $chan);
        channel::edit($channel['name'], $project_label->getValue(), $project_link->getValue(), $contact_name->getValue(), $contact_email->getValue());
        if ($is_active->getValue()) {
            channel::activate($channel['name']);
        } else {
            channel::deactivate($channel['name']);
        }
        echo "<div class=\"success\">Changes saved</div>\n";
    } catch (Exception $exception) {
예제 #5
0
 /**
  * Property getter interceptor to handle "uri" and "host" special cases.
  *
  * @param string $property The property to retrieve
  * 
  * @return mixed
  */
 public function __get($property)
 {
     switch ($property) {
         case 'uri':
             if ($this->_uri !== null) {
                 return $this->_uri->getURL();
             }
             return null;
         case 'proxy':
             return $this->_proxy;
         case 'path':
             if ($this->_uri === null) {
                 return null;
             }
             if ($this->httpVersion == self::HTTP_VERSION_1_0 || $this->proxy) {
                 // if http 1.0 or proxy given, the request uri must be absolute
                 return $this->_uri->getURL();
             }
             if (($path = $this->_uri->getPath()) === false) {
                 $path = '/';
             }
             if (($query = $this->_uri->getQuery()) !== false) {
                 $path .= '?' . $query;
             }
             if (($fragment = $this->_uri->getFragment()) !== false) {
                 $path .= '#' . $fragment;
             }
             return $path;
         case 'host':
             if (isset($this->headers['host'])) {
                 return trim($this->headers['host']);
             }
             if ($this->_proxy !== null) {
                 return $this->_proxy;
             }
             if ($this->_uri !== null) {
                 $host = $this->_uri->getHost();
                 if (($port = $this->_uri->getPort()) !== false) {
                     $host .= ':' . $port;
                 }
             }
             return $host;
         case 'port':
             $port = $this->_uri->getPort();
             if (!is_numeric($port)) {
                 return $this->isSecure() ? 443 : 80;
             }
             return $port;
         case 'connection':
             if ($this->_connection === null) {
                 include_once 'HTTP/Connection.php';
                 $this->_connection = HTTP_Connection::factory('Socket');
             }
             return $this->_connection;
         default:
             return parent::__get($property);
     }
 }
예제 #6
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;
 }
예제 #7
0
 /**
  * This is a regression test to test that recovering from
  * a wrongly encoded URL is possible.
  *
  * It was requested as Request #19684 on 2011-12-31 02:07 UTC
  * that redirects containing spaces should work.
  *
  * @return void
  */
 public function test19684()
 {
     // Location: URL obtained Thu, 25 Apr 2013 20:51:31 GMT
     $urlWithSpace = 'http://www.sigmaaldrich.com/catalog/search?interface=CAS N' . 'o.&term=108-88-3&lang=en&region=US&mode=match+partialmax&N=0+2200030' . '48+219853269+219853286';
     $urlCorrect = 'http://www.sigmaaldrich.com/catalog/search?interface=CAS%20N' . 'o.&term=108-88-3&lang=en&region=US&mode=match+partialmax&N=0+2200030' . '48+219853269+219853286';
     $url = new Net_URL2($urlWithSpace);
     $this->assertTrue($url->isAbsolute());
     $urlPart = parse_url($urlCorrect, PHP_URL_PATH);
     $this->assertSame($urlPart, $url->getPath());
     $urlPart = parse_url($urlCorrect, PHP_URL_QUERY);
     $this->assertSame($urlPart, $url->getQuery());
     $this->assertSame($urlCorrect, (string) $url);
     $input = 'http://example.com/get + + to my nose/';
     $expected = 'http://example.com/get%20+%20+%20to%20my%20nose/';
     $actual = new Net_URL2($input);
     $this->assertEquals($expected, $actual);
     $actual->normalize();
 }