Subject: | url() and self_url() act inconsistently for Server Side Includes |
Date: | Mon, 11 Dec 2006 14:23:03 -0800 |
To: | bug-CGI.pm [...] rt.cpan.org |
From: | Brian Salomaki <salomaki [...] stanford.edu> |
I am including a Perl script within an HTML page using Apache's
<!--#include virtual="script.pl" --> syntax and trying to use this
script to generate a form that will then be sent back to the same HTML
page for processing.
It seems like the straightforward solution would be to use
CGI::self_url(), but this doesn't always work. I was first running my
script over HTTPS and it worked fine, generating a URL such as
"https://server/page.html". When switching to using normal HTTP, the
output of self_url() ends up being something like
"included://server/page.html", which is not a useful/valid URL.
Digging into the code a little bit, I see that this is coming from the
method "protocol()" which will return HTTPS for requests over port 443,
but otherwise return the environment variable SERVER_PROTOCOL. When
using Server-Side Includes, SERVER_PROTOCOL gets set to INCLUDED, hence
the resulting URL.
I could hack a fix for now and replace "included://" with "http://"
after generating the URL, but it seems like CGI.pm should take a stand
one way or the other and either always generate valid URLs (preferable),
or always say "included" when the script is included, even if it's
included from a page that uses HTTPS.