How to define a protocol (http vs https) using Perl CGI.pm

I am editing a CGI Perl application that performs special processing on startup under HTTPS.

I'm currently trying to detect it, manually looking for "https: //" in the request URI:

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

Is there a slightly cleaner way to do this?

+6
perl cgi
source share
2 answers

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

works with HTTPS environment variables that are present when SSL is enabled. Can be used to determine if SSL is enabled.

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

+10
source

Use $ ENV {'HTTPS'}

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

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

+1
source

All Articles