nutshell has asked for the wisdom of the Perl Monks concerning the following question:

Is there a guaranteed safe way of detecting if a URL must be accessed via https?

if ($ENV{HTTPS}) returns true even when the URL isn't a https sometimes.

So basically, I'm asking if there's an alternative method, from the one I used above, to checking if one needs to use https.

--nutshell

Replies are listed 'Best First'.
Re: $ENV{HTTPS} not consistent
by waswas-fng (Curate) on Nov 23, 2002 at 20:31 UTC
    If you are using cgi.pm you can get the calling url by doing:
    $myself = $query->url();
    then test for https or http...

    -Waswas

      If you're going to use CGI.pm, then it would be quicker to use the https method (or function, if you add :ssl to the import list) to see if SSL is enabled...

      if ($query->https) { ... }

          --k.


Re: $ENV{HTTPS} not consistent
by PodMaster (Abbot) on Nov 24, 2002 at 14:07 UTC
    A URL is just a string conforming to the URL specification. If you've got a well formed URL, it should tell you how it needs to be accessed.
    use URI::URL; my $b = new URI::URL('httPs://foo.bar.com/baz?brd#red'); print "$b must be accessed using https " if $b->scheme eq 'https'; __END__ https://foo.bar.com/baz?brd#red must be accessed using https
    Your webserver should be controlling whether or not $ENV{HTTPS} is set. All CGI.pm does is check $ENV{HTTPS}. If your webserver sets $ENV{HTTPS} when a resource isn't requested during a SSL session, you should get a new webserver (i highly doubt this would happen).

    After your program is invoked, you can set $ENV{HTTPS} how you please, so be careful.

    Also, if you're running your program from a shell, you're in charge of your environment (in perl, the %ENV hash), so be careful not to set HTTPS.


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    ** The Third rule of perl club is a statement of fact: pod is sexy.