Lets get rid of this global..Symfony's request provides isSecure method which is better

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ParisLiakos’s picture

Status: Active » Postponed

well, i ll wait for #1847768: Remove ip_address() i kinda have to do the same work i did there already

ParisLiakos’s picture

Assigned: ParisLiakos » Unassigned
Issue tags: +Novice

wont be that hard after the issue above is in, so unnassigning and tagging novice
Replace $is_https global variable with Drupal::request()->isSecure();

ParisLiakos’s picture

Status: Postponed » Active

blocker is in:)

kid_icarus’s picture

Status: Active » Needs review
FileSize
14.12 KB

Ok, here is my first attempt. I think this is pretty close to there, except for one little piece.

I'm confused on how to treat this little snippet at the bottom of core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php (lines 470-477).

I'm not quite sure what this is doing, but what raises a red flag for me is assigning $is_https to TRUE:

    // Test HTTPS via current URL scheme.
    $temp_https = $is_https;
    $is_https = TRUE;
    $italian_url = url('admin', array('language' => $languages['it'], 'script' => ''));
    $correct_link = 'https://' . $link;
    $this->assertTrue($italian_url == $correct_link, format_string('The url() function returns the right URL (via current URL scheme) (@url) in accordance with the chosen language', array('@url' => $italian_url)));
    $is_https = $temp_https;
  }

Feedback greatly appreciated :)

Status: Needs review » Needs work

The last submitted patch, drupal-replace_is_https-1960344-4.patch, failed testing.

Berdir’s picture

+++ b/core/modules/system/lib/Drupal/system/Tests/Session/SessionHttpsTest.phpundefined
@@ -30,9 +30,8 @@ public static function getInfo() {
-    if ($is_https) {
+    if (Drupal::request()->isSecure()) {

If you use this in classes, you need \Drupal

ParisLiakos’s picture

thank you kid_icarus!
in drupal_settings_initialize() is probably too early, we dont even have a kernel yet, so i guess we can leave the old logic there but just remove the global declaration on the top

about the test, you should create a dummy request in the test setUp() function, store it to $this->request and set it to the container..then when it is assigning the global variable to TRUE you could set the server https variable to "on" or 1

Something like this:

use Symfony\Component\HttpFoundation\Request;

function setUp() {
  $this->request = Request::create('http://example.com/');
  $this->container->set('request', $this->request);
}

function testHttps() {
  // Now isSecure() returns TRUE
  $this->request->server->set('HTTPS', 1);
}
kid_icarus’s picture

@Berdir @rootawc

Thank you for the feedback :) I'll address this tonight!

tsphethean’s picture

This is also a sub-task of #1956180: [meta] Remove global variables

ParisLiakos’s picture

Status: Needs work » Needs review
FileSize
11.39 KB

happened to be in the hood..here we go

Status: Needs review » Needs work

The last submitted patch, drupal-replace_is_https-1960344-10.patch, failed testing.

ParisLiakos’s picture

Status: Needs work » Needs review
FileSize
634 bytes
11.67 KB

what a nice hacky way we have to test https:)

Crell’s picture

Status: Needs review » Reviewed & tested by the community

The conversions in #12 all look reasonable. Thanks, team!

Damien Tournoud’s picture

In drupal_settings_initialize() is probably too early, we dont even have a kernel yet, so i guess we can leave the old logic there but just remove the global declaration on the top

Yes, that's part of the bootstrap cleanup that need to happen. Our whole container (and as a consequence the whole kernel) depends on the request (because the configuration path depends on the request). So we need to change the bootstrap from:

$kernel = new DrupalKernel();
$kernel->boot();
$request = Request::createFromGlobals();
$response = $kernel->handle($request)->prepare($request)->send();

... into something more like:

$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request);
$kernel->boot();
$response = $kernel->handle($request)->prepare($request)->send();

And at the same time, we can implement DrupalKernel::createForSite($url) for command line tools like Drush to use.

alexpott’s picture

Status: Reviewed & tested by the community » Postponed
ParisLiakos’s picture

Status: Postponed » Needs review
FileSize
11.63 KB

issue above has no longer avoid commit conflicts tag, here is a reroll since previous patch stopped applying

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

back to rtbc

alexpott’s picture

Title: Replace $is_https global with Request::isSecure() » Change notification: Replace $is_https global with Request::isSecure()
Priority: Normal » Critical
Status: Reviewed & tested by the community » Active
Issue tags: +Needs change record

I think #14 is part of a larger issue and this patch gets us some of the way there and removes a global to boot :)

I've tested installation under https and general usage everything appears to be working just fine.

Committed 2784f48 and pushed to 8.x. Thanks!

ParisLiakos’s picture

Title: Change notification: Replace $is_https global with Request::isSecure() » Replace $is_https global with Request::isSecure()
Status: Active » Fixed
Issue tags: -Needs change record
ParisLiakos’s picture

Priority: Critical » Normal

status

Automatically closed -- issue fixed for 2 weeks with no activity.