How to code in Perl CGI to include action with https, not http

Viewed 452

I have a server behind a load balancer. The LB translates out of https into http so the web server only sees http.

I have a perl script that uses CGI standard to generate an input form using

start_form( -action=>url())

Right now, the url in the HTML points to the http version of the url, not the https. What is the cleanest way to get it to always use https (if https is being used by the user)?

I've tried "-rewrite" as both 0 and 1 and that didn't make the difference.

1 Answers

At least according to the documentation and the code of CGI.pm, url() and url( full => 1) should both return https:// if your CGI script was served from an https:// URL. If the load balancer strips https and does not provide the appropriate headers, you can set $ENV{HTTPS} to ON to fake that in your script yourself:

#!perl
use strict;
use warnings;

use CGI qw(url);

$ENV{HTTPS} = 'ON';
print url();

See also

CGI

Related