Subject: | Strip port before redirecting |
If the original URI had a port, then this port will be retained in the redirected https URI. I think it's nearly impossible (or at least difficult to implement) to serve both http or https from the same port.
A simple solution would be to strip the port from the req.host field:
(my $host_without_port = $req->host) =~ s{:\d+$}{};
my $url = 'https://' . $host_without_port . $req->path;
While at this, maybe it would be a good idea to add a configuration setting to change the https port, if it's necessary. Possible implementation (completely untested):
my $port = '';
my $plugin_settings = plugin_setting;
if ($plugin_settings->{https_port}) {
$port = ":$plugin_settings->{https_port}";
}
my $url = 'https://' . $host_without_port . $port . $req->path;