You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Matisse Enzer <ma...@hamparts.com> on 2003/10/01 22:23:43 UTC

Scope of Apache request object and Apache::Session scoping.

In answer to another question Perrin Harkins <pe...@elem.com> wrote:

>  I suggest you go over the code where you use the session hash very
>  carefully and make sure it goes out of scope at the end.

I'm sticking a reference to the session hash in the Apache request object:

    $r->pnotes($auth_name => \%session );

This is under mod_perl 2

I'm doing this in the belief that the request object goes out of 
scope when Apache finishes handling the request, is this correct?

-- 
------------------------------------------
Matisse Enzer
Doodlelab Inc.
415-925-5294 ext. 212 (office)
415-225-6703 (mobile)

Re: mod_perl 2: APR::URI scheme and path_info

Posted by Matisse Enzer <ma...@hamparts.com>.
Thanks,

I'll use the

     return 'https' if uc($self->https()) eq 'ON';

approach.


At 5:06 PM -0700 10/2/03, Stas Bekman wrote:
>Matisse Enzer wrote:
>>
>>
>>
>>-------------8<---------- Start Bug Report ------------8<----------
>>1. Problem Description:
>>
>>I tried:
>>    my $scheme = APR::URI->parse($r->pool, $r->uri)->scheme;
>>
>>and it didn't seem to work. My server is on port 9000 but I got 
>>nothing in $scheme.
>
>Ai, my bad, sorry about that. I *should* have tested that.
>
>I don't think you can get the request's scheme, because the server 
>doesn't know it. it's only used by the client. The server gets only 
>the request URI.
>
>You can get the scheme only if you know the whole thing, e.g.:
>
>   APR::URI->parse($r->pool, "http://localhost:9000/foo/bar")->scheme;
>
>You can check what's the currently used protocol with $r->protocol, 
>but it'll be the same with http:// and https://. CGI.pm does:
>
>sub protocol {
>     local($^W)=0;
>     my $self = shift;
>     return 'https' if uc($self->https()) eq 'ON';
>     return 'https' if $self->server_port == 443;
>     my $prot = $self->server_protocol;
>     my($protocol,$version) = split('/',$prot);
>     return "\L$protocol\E";
>}
>
>so you can either use CGI.pm or copy it away.
>
>__________________________________________________________________
>Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
>http://stason.org/     mod_perl Guide ---> http://perl.apache.org
>mailto:stas@stason.org http://use.perl.org http://apacheweek.com
>http://modperlbook.org http://apache.org   http://ticketmaster.com


-- 
------------------------------------------
Matisse Enzer
Doodlelab Inc.
415-925-5294 ext. 212 (office)
415-225-6703 (mobile)

Re: mod_perl 2: APR::URI scheme and path_info

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Stas Bekman wrote:
> Matisse Enzer wrote:
> 
>>
>>
>>
>> -------------8<---------- Start Bug Report ------------8<----------
>> 1. Problem Description:
>>
>> I tried:
>>    my $scheme = APR::URI->parse($r->pool, $r->uri)->scheme;
>>
>> and it didn't seem to work. My server is on port 9000 but I got 
>> nothing in $scheme.
> 
> 
> Ai, my bad, sorry about that. I *should* have tested that.
> 
> I don't think you can get the request's scheme, because the server 
> doesn't know it. it's only used by the client. The server gets only the 
> request URI.

there was a way to do this in mod_perl 1.0.  I'll take a look tomorrow and 
see if the same functionality was copied over.

--Geoff


Re: mod_perl 2: APR::URI scheme and path_info

Posted by Stas Bekman <st...@stason.org>.
Matisse Enzer wrote:
> 
> 
> 
> -------------8<---------- Start Bug Report ------------8<----------
> 1. Problem Description:
> 
> I tried:
>    my $scheme = APR::URI->parse($r->pool, $r->uri)->scheme;
> 
> and it didn't seem to work. My server is on port 9000 but I got nothing 
> in $scheme.

Ai, my bad, sorry about that. I *should* have tested that.

I don't think you can get the request's scheme, because the server doesn't 
know it. it's only used by the client. The server gets only the request URI.

You can get the scheme only if you know the whole thing, e.g.:

   APR::URI->parse($r->pool, "http://localhost:9000/foo/bar")->scheme;

You can check what's the currently used protocol with $r->protocol, but it'll 
be the same with http:// and https://. CGI.pm does:

sub protocol {
     local($^W)=0;
     my $self = shift;
     return 'https' if uc($self->https()) eq 'ON';
     return 'https' if $self->server_port == 443;
     my $prot = $self->server_protocol;
     my($protocol,$version) = split('/',$prot);
     return "\L$protocol\E";
}

so you can either use CGI.pm or copy it away.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: mod_perl 2: APR::URI scheme and path_info

Posted by Matisse Enzer <ma...@hamparts.com>.


-------------8<---------- Start Bug Report ------------8<----------
1. Problem Description:

I tried:
    my $scheme = APR::URI->parse($r->pool, $r->uri)->scheme;

and it didn't seem to work. My server is on port 9000 but I got 
nothing in $scheme.



At 4:53 PM -0700 10/1/03, Stas Bekman wrote:
>Matisse Enzer wrote:
>>     my $uri = APR::URI->parse;
>>
>>I want to find out what the scheme (http, https) was for the current request.
>
>APR::URI->parse($r->pool, $r->uri)->scheme;
>
>>I also want to find out (and maybe set) the path_info
>>
>>What's the right way to do this?
>
>$path_info = $r->path_info;
>
>$r->path_info($path_info);



2. Used Components and their Configuration:

*** mod_perl version 1.9910

*** using 
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/Apache/BuildConfig.pm
*** Makefile.PL options:
   MP_AP_PREFIX   => /usr/local/apache2
   MP_COMPAT_1X   => 1
   MP_GENERATE_XS => 1
   MP_LIBNAME     => mod_perl
   MP_USE_DSO     => 1
   MP_USE_STATIC  => 1


*** /usr/local/apache2/bin/httpd -V
Server version: Apache/2.0.47
Server built:   Sep 24 2003 11:08:28
Server's Module Magic Number: 20020903:4
Architecture:   32-bit
Server compiled with....
  -D APACHE_MPM_DIR="server/mpm/prefork"
  -D APR_HAS_SENDFILE
  -D APR_HAS_MMAP
  -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
  -D APR_USE_SYSVSEM_SERIALIZE
  -D APR_USE_PTHREAD_SERIALIZE
  -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
  -D APR_HAS_OTHER_CHILD
  -D AP_HAVE_RELIABLE_PIPED_LOGS
  -D HTTPD_ROOT="/usr/local/apache2"
  -D SUEXEC_BIN="/usr/local/apache2/bin/suexec"
  -D DEFAULT_PIDLOG="logs/httpd.pid"
  -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
  -D DEFAULT_LOCKFILE="logs/accept.lock"
  -D DEFAULT_ERRORLOG="logs/error_log"
  -D AP_TYPES_CONFIG_FILE="conf/mime.types"
  -D SERVER_CONFIG_FILE="conf/httpd.conf"


*** /usr/bin/perl -V
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
   Platform:
     osname=linux, osvers=2.4.21-1.1931.2.382.entsmp, 
archname=i386-linux-thread-multi
     uname='linux str'
     config_args='-des -Doptimize=-O2 -g -pipe -march=i386 -mcpu=i686 
-Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc 
-Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr 
-Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr 
-Dotherlibdirs=/usr/lib/perl5/5.8.0 -Duseshrplib -Dusethreads 
-Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db 
-Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio 
-Dinstallusrbinperl -Ubincompat5005 -Uversiononly 
-Dpager=/usr/bin/less -isr'
     hint=recommended, useposix=true, d_sigaction=define
     usethreads=define use5005threads=undef'
  useithreads=define usemultiplicity=
     useperlio= d_sfio=undef uselargefiles=define usesocks=undef
     use64bitint=undef use64bitall=un uselongdouble=
     usemymalloc=, bincompat5005=undef
   Compiler:
     cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE 
-DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing 
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 
-I/usr/include/gdbm',
     optimize='',
     cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS 
-DDEBUGGING -fno-strict-aliasing -I/usr/local/include 
-I/usr/include/gdbm'
     ccversion='', gccversion='3.2.2 20030222 (Red Hat Linux 
3.2.2-5)', gccosandvers=''
gccversion='3.2.2 200302'
     intsize=r, longsize=r, ptrsize=5, doublesize=8, byteorder=1234
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
     ivtype='long'
k', ivsize=4'
ivtype='l, nvtype='double'
o_nonbl', nvsize=, Off_t='', lseeksize=8
     alignbytes=4, prototype=define
   Linker and Libraries:
     ld='gcc'
l', ldflags =' -L/u'
     libpth=/usr/local/lib /lib /usr/lib
     libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
     perllibs=
     libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libper
     gnulibc_version='2.3.2'
   Dynamic Linking:
     dlsrc=dl_dlopen.xs, dlext=so', d_dlsymun=undef, 
ccdlflags='-rdynamic 
-Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
     cccdlflags='-fPIC'
ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5', lddlflags='s 
Unicode/Normalize XS/A'


Characteristics of this binary (from libperl):
   Compile-time options: DEBUGGING MULTIPLICITY USE_ITHREADS 
USE_LARGE_FILES PERL_IMPLICIT_CONTEXT
   Locally applied patches:
         MAINT18379
   Built under linux
   Compiled at Aug 13 2003 11:47:58
   %ENV:
     PERL_LWP_USE_HTTP_10="1"
   @INC:
     /usr/lib/perl5/5.8.0/i386-linux-thread-multi
     /usr/lib/perl5/5.8.0
     /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
     /usr/lib/perl5/site_perl/5.8.0
     /usr/lib/perl5/site_perl
     /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
     /usr/lib/perl5/vendor_perl/5.8.0
     /usr/lib/perl5/vendor_perl
     /usr/lib/perl5/5.8.0/i386-linux-thread-multi
     /usr/lib/perl5/5.8.0
     .

3. This is the core dump trace: (if you get a core dump):

   no core dump

This report was generated by /usr/bin/mp2bug on Thu Oct  2 23:47:18 2003 GMT.

-------------8<---------- End Bug Report --------------8<----------
-- 
------------------------------------------
Matisse Enzer
Doodlelab Inc.
415-925-5294 ext. 212 (office)
415-225-6703 (mobile)

Re: mod_perl 2: APR::URI scheme and path_info

Posted by Stas Bekman <st...@stason.org>.
Matisse Enzer wrote:
>     my $uri = APR::URI->parse;
> 
> I want to find out what the scheme (http, https) was for the current 
> request.

APR::URI->parse($r->pool, $r->uri)->scheme;

> I also want to find out (and maybe set) the path_info
> 
> What's the right way to do this?

$path_info = $r->path_info;

$r->path_info($path_info);


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


mod_perl 2: APR::URI scheme and path_info

Posted by Matisse Enzer <ma...@hamparts.com>.
	my $uri = APR::URI->parse;

I want to find out what the scheme (http, https) was for the current request.
I also want to find out (and maybe set) the path_info

What's the right way to do this?

-- 
------------------------------------------
Matisse Enzer
Doodlelab Inc.
415-925-5294 ext. 212 (office)
415-225-6703 (mobile)

Re: Scope of Apache request object and Apache::Session scoping.

Posted by Perrin Harkins <pe...@elem.com>.
On Wed, 2003-10-01 at 16:23, Matisse Enzer wrote:
> I'm sticking a reference to the session hash in the Apache request object:
> 
>     $r->pnotes($auth_name => \%session );
> 
> This is under mod_perl 2
> 
> I'm doing this in the belief that the request object goes out of 
> scope when Apache finishes handling the request, is this correct?

Yes.  That's a good approach to caching the session for the length of a
request.

- Perrin

Re: Scope of Apache request object and Apache::Session scoping.

Posted by Praveen Ray <pr...@crcnet1.com>.
Good Question. Does $r get freed after every request?
In any case, best is to install a PerlCleanupHandler and set untie
%$session in it.

On Wed, 2003-10-01 at 16:23, Matisse Enzer wrote:
> In answer to another question Perrin Harkins <pe...@elem.com> wrote:
> 
> >  I suggest you go over the code where you use the session hash very
> >  carefully and make sure it goes out of scope at the end.
> 
> I'm sticking a reference to the session hash in the Apache request object:
> 
>     $r->pnotes($auth_name => \%session );
> 
> This is under mod_perl 2
> 
> I'm doing this in the belief that the request object goes out of 
> scope when Apache finishes handling the request, is this correct?