예제 #1
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_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;
 }
예제 #2
0
 /**
  * Sets the configuration parameter(s)
  *
  * The following parameters are available:
  * <ul>
  *   <li> 'adapter'           - adapter to use (string)</li>
  *   <li> 'connect_timeout'   - Connection timeout in seconds (integer)</li>
  *   <li> 'timeout'           - Total number of seconds a request can take.
  *                              Use 0 for no limit, should be greater than
  *                              'connect_timeout' if set (integer)</li>
  *   <li> 'use_brackets'      - Whether to append [] to array variable names (bool)</li>
  *   <li> 'protocol_version'  - HTTP Version to use, '1.0' or '1.1' (string)</li>
  *   <li> 'buffer_size'       - Buffer size to use for reading and writing (int)</li>
  *   <li> 'store_body'        - Whether to store response body in response object.
  *                              Set to false if receiving a huge response and
  *                              using an Observer to save it (boolean)</li>
  *   <li> 'local_ip'          - Specifies the IP address that will be used for accessing
  *                              the network (string)</li>
  *   <li> 'proxy_type'        - Proxy type, 'http' or 'socks5' (string)</li>
  *   <li> 'proxy_host'        - Proxy server host (string)</li>
  *   <li> 'proxy_port'        - Proxy server port (integer)</li>
  *   <li> 'proxy_user'        - Proxy auth username (string)</li>
  *   <li> 'proxy_password'    - Proxy auth password (string)</li>
  *   <li> 'proxy_auth_scheme' - Proxy auth scheme, one of HTTP_Request2::AUTH_* constants (string)</li>
  *   <li> 'proxy'             - Shorthand for proxy_* parameters, proxy given as URL,
  *                              e.g. 'socks5://localhost:1080/' (string)</li>
  *   <li> 'ssl_verify_peer'   - Whether to verify peer's SSL certificate (bool)</li>
  *   <li> 'ssl_verify_host'   - Whether to check that Common Name in SSL
  *                              certificate matches host name (bool)</li>
  *   <li> 'ssl_cafile'        - Cerificate Authority file to verify the peer
  *                              with (use with 'ssl_verify_peer') (string)</li>
  *   <li> 'ssl_capath'        - Directory holding multiple Certificate
  *                              Authority files (string)</li>
  *   <li> 'ssl_local_cert'    - Name of a file containing local cerificate (string)</li>
  *   <li> 'ssl_passphrase'    - Passphrase with which local certificate
  *                              was encoded (string)</li>
  *   <li> 'digest_compat_ie'  - Whether to imitate behaviour of MSIE 5 and 6
  *                              in using URL without query string in digest
  *                              authentication (boolean)</li>
  *   <li> 'follow_redirects'  - Whether to automatically follow HTTP Redirects (boolean)</li>
  *   <li> 'max_redirects'     - Maximum number of redirects to follow (integer)</li>
  *   <li> 'strict_redirects'  - Whether to keep request method on redirects via status 301 and
  *                              302 (true, needed for compatibility with RFC 2616)
  *                              or switch to GET (false, needed for compatibility with most
  *                              browsers) (boolean)</li>
  * </ul>
  *
  * @param string|array $nameOrConfig configuration parameter name or array
  *                                   ('parameter name' => 'parameter value')
  * @param mixed        $value        parameter value if $nameOrConfig is not an array
  *
  * @return   HTTP_Request2
  * @throws   HTTP_Request2_LogicException If the parameter is unknown
  */
 public function setConfig($nameOrConfig, $value = null)
 {
     if (is_array($nameOrConfig)) {
         foreach ($nameOrConfig as $name => $value) {
             $this->setConfig($name, $value);
         }
     } elseif ('proxy' == $nameOrConfig) {
         $url = new Net_URL2($value);
         $this->setConfig(array('proxy_type' => $url->getScheme(), 'proxy_host' => $url->getHost(), 'proxy_port' => $url->getPort(), 'proxy_user' => rawurldecode($url->getUser()), 'proxy_password' => rawurldecode($url->getPassword())));
     } else {
         if (!array_key_exists($nameOrConfig, $this->config)) {
             throw new HTTP_Request2_LogicException("Unknown configuration parameter '{$nameOrConfig}'", HTTP_Request2_Exception::INVALID_ARGUMENT);
         }
         $this->config[$nameOrConfig] = $value;
     }
     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;
 }