https.php

Fake an HTTPS request, for use during testing.

File

drupal/core/modules/system/tests/https.php
View source
<?php

/**
 * @file
 * Fake an HTTPS request, for use during testing.
 */
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;

// Set a global variable to indicate a mock HTTPS request.
$is_https_mock = empty($_SERVER['HTTPS']);

// Change to HTTPS.
$_SERVER['HTTPS'] = 'on';
foreach ($_SERVER as $key => $value) {
  $_SERVER[$key] = str_replace('core/modules/system/tests/https.php', 'index.php', $value);
  $_SERVER[$key] = str_replace('http://', 'https://', $_SERVER[$key]);
}

// Change current directory to the Drupal root.
chdir('../../../..');
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';

// Make sure this file can only be used by simpletest.
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
if (!drupal_valid_test_ua()) {
  header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
  exit;
}

// Continue with normal request handling.
$request = Request::createFromGlobals();
drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
$kernel = new DrupalKernel('prod', FALSE, drupal_classloader(), FALSE);
$response = $kernel
  ->handle($request)
  ->prepare($request)
  ->send();
$kernel
  ->terminate($request, $response);

Constants

Namesort descending Description
DRUPAL_ROOT