Anirvan
Anirvan

Reputation: 6354

How do I identify the protocol (http vs. https) using Perl's CGI.pm

I'm editing a Perl CGI application that does special processing when run under HTTPS.

Right now, I'm trying to detect it by manually looking for 'https://' in the request URI:

    my $is_secure = $cgi->request_uri =~ m{^https://};

Is there a slightly cleaner way of doing this?

Upvotes: 7

Views: 4442

Answers (2)

Justin
Justin

Reputation: 571

Use $ENV{'HTTPS'}

my $is_secure = $ENV{'HTTPS'};

Or perhaps better, just use $ENV{'HTTPS'} instead of $is_secure

Upvotes: 1

CanSpice
CanSpice

Reputation: 35808

CGI.pm has an https() method that, according to the documentation:

operates on the HTTPS environment variables present when the SSL protocol is in effect. Can be used to determine whether SSL is turned on.

This is probably what you're looking for. Without parameters, it returns a list of HTTPS environment variables.

Upvotes: 10

Related Questions