简体   繁体   English

如何使用Perl的CGI.pm识别协议(http与https)

[英]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. 我正在编辑一个在HTTPS下运行时进行特殊处理的Perl CGI应用程序。

Right now, I'm trying to detect it by manually looking for 'https://' in the request URI: 现在,我试图通过在请求URI中手动查找“https://”来检测它:

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

Is there a slightly cleaner way of doing this? 有一个稍微清洁的方式这样做?

CGI.pm has an https() method that, according to the documentation : CGI.pm有一个https()方法,根据文档

operates on the HTTPS environment variables present when the SSL protocol is in effect. 对SSL协议生效时存在的HTTPS环境变量进行操作。 Can be used to determine whether SSL is turned on. 可用于确定SSL是否已打开。

This is probably what you're looking for. 这可能就是你要找的东西。 Without parameters, it returns a list of HTTPS environment variables. 如果没有参数,它将返回HTTPS环境变量列表。

Use $ENV{'HTTPS'} 使用$ ENV {'HTTPS'}

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

Or perhaps better, just use $ENV{'HTTPS'} instead of $is_secure 或者更好,只需使用$ ENV {'HTTPS'}而不是$ is_secure

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM