Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176

This commit is contained in:
Pantheon Automation 2015-08-17 17:00:26 -07:00 committed by Greg Anderson
commit 9921556621
13277 changed files with 1459781 additions and 0 deletions

View file

@ -0,0 +1,70 @@
<?php
/**
* @file
* Contains \Drupal\Core\Http\Client.
*/
namespace Drupal\Core\Http;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Site\Settings;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Event\SubscriberInterface;
/**
* Drupal default HTTP client class.
*/
class Client extends GuzzleClient {
/**
* {@inheritdoc}
*/
public function __construct(array $config = []) {
$default_config = array(
// Security consideration: we must not use the certificate authority
// file shipped with Guzzle because it can easily get outdated if a
// certificate authority is hacked. Instead, we rely on the certificate
// authority file provided by the operating system which is more likely
// going to be updated in a timely fashion. This overrides the default
// path to the pem file bundled with Guzzle.
'verify' => TRUE,
'timeout' => 30,
'headers' => array(
'User-Agent' => 'Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . static::getDefaultUserAgent(),
),
);
// The entire config array is merged/configurable to allow Guzzle client
// options outside of 'defaults' to be changed, such as 'adapter', or
// 'message_factory'.
$config = NestedArray::mergeDeep(array('defaults' => $default_config), $config, Settings::get('http_client_config', array()));
parent::__construct($config);
}
/**
* Attaches an event subscriber.
*
* @param \GuzzleHttp\Event\SubscriberInterface $subscriber
* The subscriber to attach.
*
* @see \GuzzleHttp\Event\Emitter::attach()
*/
public function attach(SubscriberInterface $subscriber) {
$this->getEmitter()->attach($subscriber);
}
/**
* Detaches an event subscriber.
*
* @param \GuzzleHttp\Event\SubscriberInterface $subscriber
* The subscriber to detach.
*
* @see \GuzzleHttp\Event\Emitter::detach()
*/
public function detach(SubscriberInterface $subscriber) {
$this->getEmitter()->detach($subscriber);
}
}

View file

@ -0,0 +1,72 @@
<?php
/**
* @file
* Contains \Drupal\Core\Http\TrustedHostsRequestFactory.
*/
namespace Drupal\Core\Http;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a request factory for requests using host verification.
*
* Because the trusted host patterns for requests are stored statically, they
* are consulted even for fake request created with Request::create(), whose
* host is 'localhost' by default. Such requests would fail host verification
* unless 'localhost' matches one of the trusted host patterns. To circumvent
* this problem, this factory injects the server variables from the main request
* into each newly created request, so that the host is correctly set even for
* fake requests and they properly pass host verification.
*
* @see \Drupal\Core\DrupalKernel::setupTrustedHosts()
*/
class TrustedHostsRequestFactory {
/**
* The host of the main request.
*
* @var string
*/
protected $host;
/**
* Creates a new TrustedHostsRequestFactory.
*
* @param string $host
* The host of the main request.
*/
public function __construct($host) {
$this->host = (string) $host;
}
/**
* Creates a new request object.
*
* @param array $query
* (optional) The query (GET) or request (POST) parameters.
* @param array $request
* (optional) An array of request variables.
* @param array $attributes
* (optioanl) An array of attributes.
* @param array $cookies
* (optional) The request cookies ($_COOKIE).
* @param array $files
* (optional) The request files ($_FILES).
* @param array $server
* (optional) The server parameters ($_SERVER).
* @param string $content
* (optional) The raw body data.
*
* @return \Symfony\Component\HttpFoundation\Request
* A new request object.
**/
public function createRequest(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null) {
if (empty($server['HTTP_HOST']) || ($server['HTTP_HOST'] === 'localhost' && $this->host !== 'localhost')) {
$server['HTTP_HOST'] = $this->host;
}
return new Request($query, $request, $attributes, $cookies, $files, $server, $content);
}
}