You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Reif Peter <ga...@adv.magwien.gv.at> on 2001/11/06 16:37:29 UTC

http or https in URL?

In a mod_perl handler I want to construct the original URL of the request. I
can construct it with r->get_server_name, r->get_server_port, r->uri and
$r->parsed_uri->query.

But how do I get the protocol, http or https.  Is there a way to find out
whether SSLEngine On is set?

Yes, I can set it with "PerlSetVar protocol https", but is there a simpler
way?

Thanks in advance,
Peter
--
/"\ ASCII Ribbon Campaign
\ /
 X Against HTML
/ \ in e-mail & news


Re: http or https in URL?

Posted by Stas Bekman <st...@stason.org>.
Reif Peter wrote:

> In a mod_perl handler I want to construct the original URL of the request. I
> can construct it with r->get_server_name, r->get_server_port, r->uri and
> $r->parsed_uri->query.
> 
> But how do I get the protocol, http or https.  Is there a way to find out
> whether SSLEngine On is set?
> 
> Yes, I can set it with "PerlSetVar protocol https", but is there a simpler
> way?


There was a long related discussion a few weeks ago. Here is what I've 
added to the guide (not online yet):


=head1 Verifying Whether A Request Was Received Over An SSL Connection

Just like C<$ENV{MODPERL}> is checked to see whether the code is run
under mod_perl, C<$ENV{HTTPS}> is set by ssl modules and therefore can
be used to check whether a request is running over SSL connection. For
example:

   print "SSL" if $ENV{HTTPS};

If C<PerlSetupEnv Off> setting is in effect, C<$ENV{HTTPS}> won't be
available, and then:

   print "SSL" if $r->subprocess_env('https');

should be used instead.

Note that it's also possible to check the scheme:

   print "SSL" if Apache::URI->parse($r)->scheme =~ m/^https/;

but it's not one hundred percent certain unless you control the server
and you know that you run a secure server on the port 443.






-- 


_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Re: http or https in URL?

Posted by Issac Goldstand <ma...@beamartyr.net>.
*sigh* Didn't we have this argument out about 2 months ago???

There's an old thread on this and most of what's being said here isn't
adding anything, but rather repeating things...  The conclusions were
basically that the best way would be to check $ENV{HTTPS}, but I seem to
recall someone pointing out that this only happens late in the request...
The port check is unreliable as that is only standard ports.  Possibly,
there might be some dvantage into seeing if mod_ssl, or another module, can
be configured to set $ENV{HTTPS} a bit earlier in the request if this is
really a problem.

  Issac

Internet is a wonderful mechanism for making a fool of
yourself in front of a very large audience.
  --Anonymous

Moving the mouse won't get you into trouble...  Clicking it might.
  --Anonymous

PGP Key 0xE0FA561B - Fingerprint:
7E18 C018 D623 A57B 7F37 D902 8C84 7675 E0FA 561B




----- Original Message -----
From: "Reif Peter" <ga...@adv.magwien.gv.at>
To: <mo...@apache.org>
Sent: Tuesday, November 06, 2001 17:37
Subject: http or https in URL?


> In a mod_perl handler I want to construct the original URL of the request.
I
> can construct it with r->get_server_name, r->get_server_port, r->uri and
> $r->parsed_uri->query.
>
> But how do I get the protocol, http or https.  Is there a way to find out
> whether SSLEngine On is set?
>
> Yes, I can set it with "PerlSetVar protocol https", but is there a simpler
> way?
>
> Thanks in advance,
> Peter
> --
> /"\ ASCII Ribbon Campaign
> \ /
>  X Against HTML
> / \ in e-mail & news
>


Re: http or https in URL?

Posted by David Young <dy...@nettonettech.com>.
This will not work all the time for all configurations. 80 is the default
port for http and 443 is the default port for https. However, just as you
may choose to run your http server on any port you wish, you may also choose
to run your https server on any port you wish.

> From: Rob Nagler <na...@bivio.net>
> Organization: bivio Software Artisans, Inc. <http://www.bivio.net>
> Date: Tue, 6 Nov 2001 08:45:45 -0700
> To: modperl@apache.org
> Subject: Re: http or https in URL?
> 
>> But how do I get the protocol, http or https.
> 
> You can check the port on $c->local_addr.  443 is https.
> 
> Rob
> 
> 
> 
> 
> 


Re: http or https in URL?

Posted by Rob Nagler <na...@bivio.net>.
> But how do I get the protocol, http or https.

You can check the port on $c->local_addr.  443 is https.

Rob