public function Request::__construct

Same name in this branch

Create a new request

Parameters

string $method HTTP method:

string|Url $url HTTP URL to connect to. The URI scheme, host header, and URI are parsed from the: full URL. If query string parameters are present they will be parsed as well.

array|Collection $headers HTTP headers:

1 call to Request::__construct()
EntityEnclosingRequest::__construct in drupal/core/vendor/guzzle/http/Guzzle/Http/Message/EntityEnclosingRequest.php
Create a new request
1 method overrides Request::__construct()
EntityEnclosingRequest::__construct in drupal/core/vendor/guzzle/http/Guzzle/Http/Message/EntityEnclosingRequest.php
Create a new request

File

drupal/core/vendor/guzzle/http/Guzzle/Http/Message/Request.php, line 109

Class

Request
HTTP request class to send requests

Namespace

Guzzle\Http\Message

Code

public function __construct($method, $url, $headers = array()) {
  $this->method = strtoupper($method);
  $this->curlOptions = new Collection();
  $this->params = new Collection();
  $this
    ->setUrl($url);
  if ($headers) {

    // Special handling for multi-value headers
    foreach ($headers as $key => $value) {
      $lkey = strtolower($key);

      // Deal with collisions with Host and Authorization
      if ($lkey == 'host') {
        $this
          ->setHeader($key, $value);
      }
      elseif ($lkey == 'authorization') {
        $parts = explode(' ', $value);
        if ($parts[0] == 'Basic' && isset($parts[1])) {
          list($user, $pass) = explode(':', base64_decode($parts[1]));
          $this
            ->setAuth($user, $pass);
        }
        else {
          $this
            ->setHeader($key, $value);
        }
      }
      else {
        foreach ((array) $value as $v) {
          $this
            ->addHeader($key, $v);
        }
      }
    }
  }
  if (!$this
    ->hasHeader('User-Agent', true)) {
    $this
      ->setHeader('User-Agent', Utils::getDefaultUserAgent());
  }
  $this
    ->setState(self::STATE_NEW);
}