7

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?

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I know this is an old question, but it was relevant to something I was looking for as well. Unfortunately, the documentation you linked to doesn't tell you how to do it, just that one can.
1

Use $ENV{'HTTPS'}

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

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

1 Comment

I'd expect most mainstream servers to have some environment variable for this even if it isn't exactly this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.