You are here

function HTTP_Request::HTTP_Request in Flickr API 5

Constructor

Sets up the object

@access public

Parameters

string The url to fetch/access:

array Associative array of parameters which can have the following keys:: <ul> <li>method - Method to use, GET, POST etc (string)</li> <li>http - HTTP Version to use, 1.0 or 1.1 (string)</li> <li>user - Basic Auth username (string)</li> <li>pass - Basic Auth password (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_pass - Proxy auth password (string)</li> <li>timeout - Connection timeout in seconds (float)</li> <li>allowRedirects - Whether to follow redirects or not (bool)</li> <li>maxRedirects - Max number of redirects to follow (integer)</li> <li>useBrackets - Whether to append [] to array variable names (bool)</li> <li>saveBody - Whether to save response body in response object property (bool)</li> <li>readTimeout - Timeout for reading / writing data over the socket (array (seconds, microseconds))</li> <li>socketOptions - Options to pass to Net_Socket object (array)</li> </ul>

1 call to HTTP_Request::HTTP_Request()
HTTP_Request::reset in phpFlickr/PEAR/HTTP/Request.php
Resets the object to its initial state (DEPRECATED). Takes the same parameters as the constructor.

File

phpFlickr/PEAR/HTTP/Request.php, line 301

Class

HTTP_Request
Class for performing HTTP requests

Code

function HTTP_Request($url = '', $params = []) {
  $this->_method = HTTP_REQUEST_METHOD_GET;
  $this->_http = HTTP_REQUEST_HTTP_VER_1_1;
  $this->_requestHeaders = array();
  $this->_postData = array();
  $this->_body = null;
  $this->_user = null;
  $this->_pass = null;
  $this->_proxy_host = null;
  $this->_proxy_port = null;
  $this->_proxy_user = null;
  $this->_proxy_pass = null;
  $this->_allowRedirects = false;
  $this->_maxRedirects = 3;
  $this->_redirects = 0;
  $this->_timeout = null;
  $this->_response = null;
  foreach ($params as $key => $value) {
    $this->{'_' . $key} = $value;
  }
  if (!empty($url)) {
    $this
      ->setURL($url);
  }

  // Default useragent
  $this
    ->addHeader('User-Agent', 'PEAR HTTP_Request class ( http://pear.php.net/ )');

  // We don't do keep-alives by default
  $this
    ->addHeader('Connection', 'close');

  // Basic authentication
  if (!empty($this->_user)) {
    $this
      ->addHeader('Authorization', 'Basic ' . base64_encode($this->_user . ':' . $this->_pass));
  }

  // Proxy authentication (see bug #5913)
  if (!empty($this->_proxy_user)) {
    $this
      ->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($this->_proxy_user . ':' . $this->_proxy_pass));
  }

  // Use gzip encoding if possible
  if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && extension_loaded('zlib')) {
    $this
      ->addHeader('Accept-Encoding', 'gzip');
  }
}