You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Clayton Cottingham <dr...@telus.net> on 2004/01/21 22:57:58 UTC

Apache::Request vs Apache->request

while i understand the difference between these two i am unsure how to
handle these back and forth. let me explain:

I have an upload module with the handler using an Apache::Request
   my $r = Apache::Request->new(
        shift,
        POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
        DISABLE_UPLOADS => 0
    );


later on i want to send all the info recieved from a file to another
module that inserts this information into a database table

rather than pass through a  LWP::Simple::get call i would like to call
the  subroutine that handles the logic directly like so:

&MYMod::Add::Add($r);

BUT i have the above subroutine pulling in the Apache->request object if
through MYMod::Add::handler


so i tried something like this in my upload module


 my $r = Apache->request;

    # Standard stuff, with added options...
    my $apr = Apache::Request->new(
        $r,
        POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
        DISABLE_UPLOADS => 0
    );

and then 
&MYMod::Add::Add($r);

but this just borks out the uplaod procedure

and nothing get processed, whereas if i just pass in the Apache::Request
it doesnt process the parameters correctly

can anyone explain the finesse i am messing up?

-- 
Clayton Cottingham - WinterMarket Networks
Virtual Reality Programming, Design & Evangelist
Phone:(604) 875-1213
Cell: (604) 506-7230
Vancouver, B.C. Canada
wintermarket@wintermarket.net
http://www.wintermarket.net
IM's icq:154964789 hotmail:drfrog666@hotmail.com
yahoo:drfrog666@yahoo.com


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Apache::Request vs Apache->request

Posted by Stas Bekman <st...@stason.org>.
Clayton Cottingham wrote:
> stas, thanks again, i owe you another espresso!

;)

> ok it seems there is some sort of disconnect with modperl , the
> apr->upload and method postm, at least in my brainpan!
> 
> as the listing are it does not pass the %args to the parseFile or
> through to the listing 2 subroutine
> 
> if the $apr and if statement lines are flipped in listing 1 handler
> subroutine stuffs then it works but the file is not
> uploaded...obviously! this is just a basic Apache->request
> 
> NOW if i keep the listings the same and take out the method=post in
> print form it cycles back to printform sub clearing the form field but
> placing the args into the form as hidden fields
> 
> if the lines are flipped to a straight Apache->request it processes fine
> 
> does this give enough info?

I dunno, it could be a bug in libapreq or your code. It takes us a lot of time 
to setup the bug/problem test cases posted here. Geoff was kind enough to 
create a self-containing Apache-Test skeleton which you can use to present 
your case. All you need to add your bug to the skeleton and make it working 
(the setup), so we can download it and run right away, and spend the time 
understanding the problem and solving it and not trying to set it up.
The link to bug-reporting-skeleton-mp1.tar.gz and explanations is here:
http://perl.apache.org/docs/1.0/guide/help.html#How_to_Report_Problems

Thanks.

__________________________________________________________________
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

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp1] [bug report] Re: Apache::Request vs Apache->request

Posted by Clayton Cottingham <dr...@telus.net>.
Stas:

sorry i did miss that, yesterday was too too hectic

ill try this now


On Thu, 2004-01-29 at 20:03, Stas Bekman wrote:
> Clayton Cottingham wrote:
> > yah its calling it properly:
> > 
> >  my $apr = Apache::Request->new(
> >         shift,
> >         POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
> >         DISABLE_UPLOADS => 0
> >     );
> > 
> > how would one make a test to make sure the file is uploading properly?
> > and what about multipart form?
> 
> Clayton, sorry, but I did tell you where to look for examples:
> http://marc.theaimsgroup.com/?l=apache-modperl&m=107541472424933&w=2
> Please scroll to the end of this email. Have you missed that part of my reply 
> by mistake? It does *exactly* what you need.
> 
> __________________________________________________________________
> 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
-- 
Clayton Cottingham - WinterMarket Networks
Virtual Reality Programming, Design & Evangelist
Phone:(604) 875-1213
Cell: (604) 506-7230
Vancouver, B.C. Canada
wintermarket@wintermarket.net
http://www.wintermarket.net
IM's icq:154964789 hotmail:drfrog666@hotmail.com
yahoo:drfrog666@yahoo.com


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp1] [bug report] Re: Apache::Request vs Apache->request

Posted by Stas Bekman <st...@stason.org>.
Clayton Cottingham wrote:
> yah its calling it properly:
> 
>  my $apr = Apache::Request->new(
>         shift,
>         POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
>         DISABLE_UPLOADS => 0
>     );
> 
> how would one make a test to make sure the file is uploading properly?
> and what about multipart form?

Clayton, sorry, but I did tell you where to look for examples:
http://marc.theaimsgroup.com/?l=apache-modperl&m=107541472424933&w=2
Please scroll to the end of this email. Have you missed that part of my reply 
by mistake? It does *exactly* what you need.

__________________________________________________________________
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

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp1] [bug report] Re: Apache::Request vs Apache->request

Posted by Clayton Cottingham <dr...@telus.net>.
yah its calling it properly:

 my $apr = Apache::Request->new(
        shift,
        POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
        DISABLE_UPLOADS => 0
    );



how would one make a test to make sure the file is uploading properly?
and what about multipart form?

##how to post the file???!!!
{
     my $response = GET '/otherthing?funk=rock&file1=README';
     chomp(my $content = $response->content);
     ok t_cmp(qr{<html><body>},
             $content,
             'OtherThing.pm');
}


works for find ing out there is a page loading   

using t_is_equal() should be able to compare the $apr objects , but im
unsure how to pull it into the tests!





again i can get this all to work if i *dont* pass a file
as soon as i start that things start wonking out

either the parameters pass *OR* the file is downloads, but i cant get
both to happen


On Thu, 2004-01-29 at 16:38, Stas Bekman wrote:
> Clayton Cottingham wrote:
> > ok thanks for the patience!
> > 
> > i managed to 
> > a) get the base bug report template to go under freebsd and 
> 
> good.
> 
> > b) had my modules fail and generate  error log 
> > 
> > which is telling me that this isnt correct:
> > 
> >  my $apr = Apache::Request->new(
> >         shift,
> >         POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
> >         DISABLE_UPLOADS => 0
> >     );
> > 
> >     my %args = $apr->args;
> > 
> > with this :
> > 
> > Odd number of elements in hash assignment at
> > /usr/home/clayton/bug-reporting-skeleton-mp1/t/PP/OtherThing.pm line 18.
> > 
> > 
> > from what ive read/been told this should be an issue correct?
> > 
> > Apache::Request should be able to pass this right?
> 
> I think, yes. check that your shift in the new() call is really getting $r and 
> not undef (e.g. not shift()'ed before).
> 
> __________________________________________________________________
> 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
-- 
Clayton Cottingham - WinterMarket Networks
Virtual Reality Programming, Design & Evangelist
Phone:(604) 875-1213
Cell: (604) 506-7230
Vancouver, B.C. Canada
wintermarket@wintermarket.net
http://www.wintermarket.net
IM's icq:154964789 hotmail:drfrog666@hotmail.com
yahoo:drfrog666@yahoo.com


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp1] [bug report] Re: Apache::Request vs Apache->request

Posted by Stas Bekman <st...@stason.org>.
Clayton Cottingham wrote:
> ok thanks for the patience!
> 
> i managed to 
> a) get the base bug report template to go under freebsd and 

good.

> b) had my modules fail and generate  error log 
> 
> which is telling me that this isnt correct:
> 
>  my $apr = Apache::Request->new(
>         shift,
>         POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
>         DISABLE_UPLOADS => 0
>     );
> 
>     my %args = $apr->args;
> 
> with this :
> 
> Odd number of elements in hash assignment at
> /usr/home/clayton/bug-reporting-skeleton-mp1/t/PP/OtherThing.pm line 18.
> 
> 
> from what ive read/been told this should be an issue correct?
> 
> Apache::Request should be able to pass this right?

I think, yes. check that your shift in the new() call is really getting $r and 
not undef (e.g. not shift()'ed before).

__________________________________________________________________
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

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp1] [bug report] Re: Apache::Request vs Apache->request

Posted by Clayton Cottingham <dr...@telus.net>.
ok thanks for the patience!

i managed to 
a) get the base bug report template to go under freebsd and 

b) had my modules fail and generate  error log 

which is telling me that this isnt correct:

 my $apr = Apache::Request->new(
        shift,
        POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
        DISABLE_UPLOADS => 0
    );

    my %args = $apr->args;

with this :

Odd number of elements in hash assignment at
/usr/home/clayton/bug-reporting-skeleton-mp1/t/PP/OtherThing.pm line 18.


from what ive read/been told this should be an issue correct?

Apache::Request should be able to pass this right?

On Thu, 2004-01-29 at 15:02, Stas Bekman wrote:
> Clayton Cottingham wrote:
> > oops! i just checked the bug.t wasnt safed after i put the changes in to
> > use PP/* modules, that should work ok right? i include it with changes
> 
> that same file was included in the original tar.
> 
> > sorry for the fud
> > 
> > also i injected the pp.conf into extra.conf.in sio there is no need to
> > include it 
> > 
> > there is nothing nessecary in my startup.pl file that needed to be
> > included for this simple example
> > 
> > 
> > i just tested again and still get same errors  from test suite
> > those being sethandler ifmodule stuff on linux and the fopen proble on
> > freebsd 
> > 
> > and i did follow the readme implicitly
> > :)
> 
> Please re-read my reply on what you did wrong, make a new package and 
> preferably upload it somewhere and post the url here, so you don't clutter the 
> list with big posts.
> 
> I'd suggest that you first try to run the skeleton after you've downloaded it, 
> without changing anything in it. Because if it doesn't work for you, obviously 
> you won't be able to present your case.
> 
> Thanks.
> 
> __________________________________________________________________
> 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
-- 
Clayton Cottingham - WinterMarket Networks
Virtual Reality Programming, Design & Evangelist
Phone:(604) 875-1213
Cell: (604) 506-7230
Vancouver, B.C. Canada
wintermarket@wintermarket.net
http://www.wintermarket.net
IM's icq:154964789 hotmail:drfrog666@hotmail.com
yahoo:drfrog666@yahoo.com


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp1] [bug report] Re: Apache::Request vs Apache->request

Posted by Stas Bekman <st...@stason.org>.
Clayton Cottingham wrote:
> oops! i just checked the bug.t wasnt safed after i put the changes in to
> use PP/* modules, that should work ok right? i include it with changes

that same file was included in the original tar.

> sorry for the fud
> 
> also i injected the pp.conf into extra.conf.in sio there is no need to
> include it 
> 
> there is nothing nessecary in my startup.pl file that needed to be
> included for this simple example
> 
> 
> i just tested again and still get same errors  from test suite
> those being sethandler ifmodule stuff on linux and the fopen proble on
> freebsd 
> 
> and i did follow the readme implicitly
> :)

Please re-read my reply on what you did wrong, make a new package and 
preferably upload it somewhere and post the url here, so you don't clutter the 
list with big posts.

I'd suggest that you first try to run the skeleton after you've downloaded it, 
without changing anything in it. Because if it doesn't work for you, obviously 
you won't be able to present your case.

Thanks.

__________________________________________________________________
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

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp1] [bug report] Re: Apache::Request vs Apache->request

Posted by Clayton Cottingham <dr...@telus.net>.
oops! i just checked the bug.t wasnt safed after i put the changes in to
use PP/* modules, that should work ok right? i include it with changes

sorry for the fud

also i injected the pp.conf into extra.conf.in sio there is no need to
include it 

there is nothing nessecary in my startup.pl file that needed to be
included for this simple example


i just tested again and still get same errors  from test suite
those being sethandler ifmodule stuff on linux and the fopen proble on
freebsd 

and i did follow the readme implicitly
:)



On Thu, 2004-01-29 at 14:18, Stas Bekman wrote:
> Clayton Cottingham wrote:
> > Hello:
> > 
> > here is as much information on this as i have currently
> > 
> > the test suite was blowing up on both freebsd and linux for different
> > reasons, its all in the error report doc
> > 
> > i guess at this point the only thing left is to try and compile
> > apache/mod-perl from scratch.. but i dont have time for that right now
> > 
> > please look over and tell me if i should proceed in that direction
> 
> well, did you read README inside the tarball? You need to put your code that's 
> not working under t/My/Bug.pm if it's a handler or insite t/cgi-bin/ if it's a 
> script. Now you need to adjust bug.t to do the request. It looks that you've 
> change t/bug.t to request /useme URI. But you didn't configure it. You need to 
> use t/conf/extra.conf.in to put any custom configuration.
> 
> So pp.conf needs to be in t/conf/extra.conf.in
> and startup.pl in t/conf/modperl_extra.pl
> 
> it'll take you some time to find your way around for the first time. Feel free 
> to ask questions, after you've referred to the docs listed in the README file.
> 
>  From your errorreport:
> 
>  > **********
>  > notes
>  > **********
>  > the reason here is because mandrake 9.2 has ifmodule commands:
>  > <IfModule mod_status.c>
>  >
>  > <IfModule mod_info.c>
>  >
>  > that wrap arond these directives
>  >
>  > how can i set them into the httpd.conf?
> 
> They are inherited from your global httpd.conf.
> 
>  > please note it trying to use httpd2 as well
> 
> You tell it which httpd to use:
> 
> t/TEST -httpd /path/to/httpd
> 
>  > ######################
>  > on freebsd
>  > ######################
>  >
>  > -bash-2.05b$  t/TEST -httpd /usr/local/apache/bin/httpd
>  > /usr/local/apache/bin/httpd -d 
> /usr/home/clayton/bug-reporting-skeleton-mp1/t -f 
> /usr/home/clayton/bug-reporting-skeleton-mp1/t/conf/httpd.conf -DAPACHE1
>  > using Apache/1.3.29
>  >
>  > waiting 60 seconds for server to start: .fopen: No such file or directory
>  > httpd: could not open document config file 
> /usr/home/clayton/bug-reporting-skeleton-mp1/t/conf/.#extra.conf
>  > ............................................................
>  > waiting 60 seconds for server to start: giving up after 61 secs
>  > !!! server failed to start! (t/logs/error_log wasn't created, start the 
> server in the debug mode)
> 
> you left a broken file after forgetting to save extra.conf in emacs: 
> t/conf/.#extra.conf, delete it and the error will go away.
> 
>  > ########
>  > errata
>  > ########
>  >
>  > not sure how to add in the fileupload procedure, please see bug.t for
>  > a how i was trying, but unfortunately i didnt get far enough in test
>  > suite to accomodate this
> 
> You can upload a real file, as in:
> modperl-2.0/t/modules/cgiupload.t
> modperl-2.0/t/response/TestModules/cgiupload.pm
> 
> Or you can cheat
> modperl-2.0/t/modules/cgi.t
> modperl-2.0/t/response/TestModules/cgi.pm
> 
> I'll add this to the testing doc.
> 
> __________________________________________________________________
> 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
-- 
Clayton Cottingham - WinterMarket Networks
Virtual Reality Programming, Design & Evangelist
Phone:(604) 875-1213
Cell: (604) 506-7230
Vancouver, B.C. Canada
wintermarket@wintermarket.net
http://www.wintermarket.net
IM's icq:154964789 hotmail:drfrog666@hotmail.com
yahoo:drfrog666@yahoo.com

Re: [mp1] [bug report] Re: Apache::Request vs Apache->request

Posted by Stas Bekman <st...@stason.org>.
[please keep on the list, thanks]

Clayton Cottingham wrote:
> hey stas!

>  > how can i set them into the httpd.conf?
> 
> They are inherited from your global httpd.conf
> 
> 
> this is what i need in i think!
> 
> LoadModule status_module      modules/mod_status.so
> LoadModule info_module        modules/mod_info.so
> AddModule mod_info.c
> AddModule mod_status.c
> 
> 
> i tried doing this by adding to the main server commonhttpd.conf and the
> http-perl.conf
> 
> and the one in the test suite t/conf/httpd.conf t/conf/extra.conf.in
> 
> and it doesnt seem to hold it in fact it erases it if i do a t/TEST
> -clean 

t/conf/httpd.conf is automatically generated. It adds stuff from your global 
httpd.conf. anything that you want to customise should be added to 
t/conf/extra.conf.in

> how can i add it in and have it keep it?
> 
> else again it reports this:
> 
> waiting 60 seconds for server to start: .Syntax error on line 80 of
> /home/drfrog/bug-reporting-skeleton-mp1/t/conf/httpd.conf:
> Invalid command 'SetHandler', perhaps mis-spelled or defined by a module
> not included in the server configuration

Looks like it doesn't have the LoadModule directive for the module containing 
this directive. Does your server installed globally work alright? You didn't 
by chance rebuilt your server with sharedlibs, but kept the old httpd.conf 
originated from the statically build server?

If for some reason it finds the wrong httpd.conf go inherit from. You can tell 
it which httpd.conf to inherit from:

t/TEST -httpd_conf /path/to/httpd.conf

t/TEST --help gives you the options

t/TEST -trace=debug does the low level debugging, so you can see what it does 
and which files it picks.



__________________________________________________________________
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

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp1] [bug report] Re: Apache::Request vs Apache->request

Posted by Stas Bekman <st...@stason.org>.
Clayton Cottingham wrote:
> Hello:
> 
> here is as much information on this as i have currently
> 
> the test suite was blowing up on both freebsd and linux for different
> reasons, its all in the error report doc
> 
> i guess at this point the only thing left is to try and compile
> apache/mod-perl from scratch.. but i dont have time for that right now
> 
> please look over and tell me if i should proceed in that direction

well, did you read README inside the tarball? You need to put your code that's 
not working under t/My/Bug.pm if it's a handler or insite t/cgi-bin/ if it's a 
script. Now you need to adjust bug.t to do the request. It looks that you've 
change t/bug.t to request /useme URI. But you didn't configure it. You need to 
use t/conf/extra.conf.in to put any custom configuration.

So pp.conf needs to be in t/conf/extra.conf.in
and startup.pl in t/conf/modperl_extra.pl

it'll take you some time to find your way around for the first time. Feel free 
to ask questions, after you've referred to the docs listed in the README file.

 From your errorreport:

 > **********
 > notes
 > **********
 > the reason here is because mandrake 9.2 has ifmodule commands:
 > <IfModule mod_status.c>
 >
 > <IfModule mod_info.c>
 >
 > that wrap arond these directives
 >
 > how can i set them into the httpd.conf?

They are inherited from your global httpd.conf.

 > please note it trying to use httpd2 as well

You tell it which httpd to use:

t/TEST -httpd /path/to/httpd

 > ######################
 > on freebsd
 > ######################
 >
 > -bash-2.05b$  t/TEST -httpd /usr/local/apache/bin/httpd
 > /usr/local/apache/bin/httpd -d 
/usr/home/clayton/bug-reporting-skeleton-mp1/t -f 
/usr/home/clayton/bug-reporting-skeleton-mp1/t/conf/httpd.conf -DAPACHE1
 > using Apache/1.3.29
 >
 > waiting 60 seconds for server to start: .fopen: No such file or directory
 > httpd: could not open document config file 
/usr/home/clayton/bug-reporting-skeleton-mp1/t/conf/.#extra.conf
 > ............................................................
 > waiting 60 seconds for server to start: giving up after 61 secs
 > !!! server failed to start! (t/logs/error_log wasn't created, start the 
server in the debug mode)

you left a broken file after forgetting to save extra.conf in emacs: 
t/conf/.#extra.conf, delete it and the error will go away.

 > ########
 > errata
 > ########
 >
 > not sure how to add in the fileupload procedure, please see bug.t for
 > a how i was trying, but unfortunately i didnt get far enough in test
 > suite to accomodate this

You can upload a real file, as in:
modperl-2.0/t/modules/cgiupload.t
modperl-2.0/t/response/TestModules/cgiupload.pm

Or you can cheat
modperl-2.0/t/modules/cgi.t
modperl-2.0/t/response/TestModules/cgi.pm

I'll add this to the testing doc.

__________________________________________________________________
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

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


[mp1] [bug report] Re: Apache::Request vs Apache->request

Posted by Clayton Cottingham <dr...@telus.net>.
Hello:

here is as much information on this as i have currently

the test suite was blowing up on both freebsd and linux for different
reasons, its all in the error report doc

i guess at this point the only thing left is to try and compile
apache/mod-perl from scratch.. but i dont have time for that right now

please look over and tell me if i should proceed in that direction




-- 
Clayton Cottingham - WinterMarket Networks
Virtual Reality Programming, Design & Evangelist
Phone:(604) 875-1213
Cell: (604) 506-7230
Vancouver, B.C. Canada
wintermarket@wintermarket.net
http://www.wintermarket.net
IM's icq:154964789 hotmail:drfrog666@hotmail.com
yahoo:drfrog666@yahoo.com

Re: Apache::Request vs Apache->request

Posted by Clayton Cottingham <dr...@telus.net>.
stas, thanks again, i owe you another espresso!

ok it seems there is some sort of disconnect with modperl , the
apr->upload and method postm, at least in my brainpan!

as the listing are it does not pass the %args to the parseFile or
through to the listing 2 subroutine

if the $apr and if statement lines are flipped in listing 1 handler
subroutine stuffs then it works but the file is not
uploaded...obviously! this is just a basic Apache->request

NOW if i keep the listings the same and take out the method=post in
print form it cycles back to printform sub clearing the form field but
placing the args into the form as hidden fields

if the lines are flipped to a straight Apache->request it processes fine

does this give enough info?


#########################
#			#
#	listing 1	#
#			#
#########################
package PP::OtherThing;

use Apache::Constants qw(OK);
use Apache::Request;
use Apache::Util qw(escape_html);
use strict;
use warnings;
use PP::UseMe;

sub handler {
#    my $apr = Apache->request;

  my $apr = Apache::Request->new(
        shift,
        POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
        DISABLE_UPLOADS => 0
    );

    my %args = $apr->args;
    warn Data::Dumper::Dumper(%args);

    if ( $apr->upload ) {
  #  if (%args){
      parseFile($apr);
    }
    else {
      printForm($apr);
    }


}

sub parseFile {
    my $r    = shift;
    my %args = $r->args;
    warn Data::Dumper::Dumper(%args);
    my $html = "<html><body>";


    my $stuff=&PP::UseMe::AddSite($r);
    $html.= "$stuff </body></html>";
    $r->send_http_header('text/html');
    $r->print($html);
}
sub printForm {
    my $r = shift;
    my %args = $r->args;

    my $forms;

    foreach (keys %args){
      $forms.="<input type=hidden name=\"$_\" value=\"$args{$_}\">\n";
    }

    $r->send_http_header('text/html');

    $r->print("<html><body>\n");
    $r->print("<h1>Upload sites</h1>");

    # Output a simple form.
    $r->print(<<EOF);
  <form enctype="multipart/form-data" name="files"
action="/PP/otherthing" method=POST>
    Excel File <input type="file" name="file1"><br>
$forms
    <input type="submit" name="submit" value="Upload these files">
  </form>
 </body></html>
EOF

    return OK;
}
1;

#########################
#			#
#	listing 2	#
#			#
#########################
package PP::UseMe;


use Data::Dumper qw(Dumper);
use strict;
use warnings;


sub handler {
    my $r    = Apache->request;
    my %args = $r->args;
    warn Data::Dumper::Dumper(%args);
    &PP::Global::print_html( $r, &AddSite($r) );
}

sub AddSite {
    my $r    = shift;
    my %args = $r->args;
    warn Data::Dumper::Dumper(%args);
    return Data::Dumper::Dumper(%args);
}

1;

-- 
Clayton Cottingham - WinterMarket Networks
Virtual Reality Programming, Design & Evangelist
Phone:(604) 875-1213
Cell: (604) 506-7230
Vancouver, B.C. Canada
wintermarket@wintermarket.net
http://www.wintermarket.net
IM's icq:154964789 hotmail:drfrog666@hotmail.com
yahoo:drfrog666@yahoo.com


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: internal_redirect to randomly named filename

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

dreamwvr@dreamwvr.com wrote:
> On Tue, Feb 03, 2004 at 11:09:31AM -0500, Geoffrey Young wrote:
> 
>>I don't see why you need to use either with internal_redirect() - just pass
>>it the URI and let Apache handle it.  you would use a subrequest (initiated
>>from eather of the lookup functions) along with $sub->run() if you wanted to
>>send the contents of the subrequest along.
> 
> (For the archives since It might be useful info.. them again maybe not.:-)
> Well, I was hoping this was the case however this is what happens..
>  [...]
>  $sub = $r->lookup_file("randfile.html"); 
>   $filename = $sub->filename();
> [...]
> $sub->internal_redirect($filename);
>   $sub->run() and return 'OK';
> 
>   if($sub->run ne 'OK') {
>    
>     $sub->log_error("Error running subrequest!");
> 
>   }
> Just tried this and I get the usual file_not_found page..
> Not Found
> 
> The requested URL /var/www/htdocs/test/randfile.html was not found on this server.
> FYI:
> If one uses the internal_redir* with lookup_file() the above err is what occurs.
> If one uses the internal_redir* with lookup_uri() and the file exists
> one does get the page. So me thinks I am missing something obvious. Is it?
> thought train was that subrequests make Apache reload the page as if it was 
> a completely new request. That way redirection would occur simularly to
> META tags redirection when set to "0" seconds. Well back to it. 

take a look at the internal_redirect docs - once you call internal_redirect
you need to return OK - no additional logic is allowed.  so, you can't both
$sub->internal_redirect() and $sub->run().

basically, if in your content handler you want Apache to redirect to a
different URI use $r->internal_redirect.

if you want to test attributes of a given URI or file (say, whether the
current $r->remote_user would be able to view the file if they accessed it
directly), then you would create a subrequest with lookup_file() or
lookup_uri().  if you find that the subrequest passes your tests, you can
$sub->run() to send the file directly to the client, or call whatever logic
you like to send your own content to the client (including
$r->internal_redirect).

HTH

--Geoff


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: internal_redirect to randomly named filename

Posted by "dreamwvr@dreamwvr.com" <dr...@dreamwvr.com>.
On Tue, Feb 03, 2004 at 11:09:31AM -0500, Geoffrey Young wrote:
> I don't see why you need to use either with internal_redirect() - just pass
> it the URI and let Apache handle it.  you would use a subrequest (initiated
> from eather of the lookup functions) along with $sub->run() if you wanted to
> send the contents of the subrequest along.
(For the archives since It might be useful info.. them again maybe not.:-)
Well, I was hoping this was the case however this is what happens..
 [...]
 $sub = $r->lookup_file("randfile.html"); 
  $filename = $sub->filename();
[...]
$sub->internal_redirect($filename);
  $sub->run() and return 'OK';

  if($sub->run ne 'OK') {
   
    $sub->log_error("Error running subrequest!");

  }
Just tried this and I get the usual file_not_found page..
Not Found

The requested URL /var/www/htdocs/test/randfile.html was not found on this server.
FYI:
If one uses the internal_redir* with lookup_file() the above err is what occurs.
If one uses the internal_redir* with lookup_uri() and the file exists
one does get the page. So me thinks I am missing something obvious. Is it?
thought train was that subrequests make Apache reload the page as if it was 
a completely new request. That way redirection would occur simularly to
META tags redirection when set to "0" seconds. Well back to it. 

 Best Regards,
dreamwvr@dreamwvr.com



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: internal_redirect to randomly named filename

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

dreamwvr@dreamwvr.com wrote:
> Hi All,
>   Since lookup_uri() is only to be used when the actual
> URI physically exists. Having said that how does not tell 
> it to pretend that a randomly generated virtual file exists?
> Is that what lookup_filename() is for? 

lookup_uri() will issue a subrequest that includes URI->filename
translation.  lookup_file() will skip over the translation part, setting
$r->filename to the file you pass in.  I suppose that you could use this to
avoid the IO if you know the file doesn't exist, but I've never tried.  from
the code it looks like it should work ok - $r->filename is set but
meaningless for dynamic documents anyway.

> I am wanting to do a 
> internal_redirect() to a virtual file whose name is always
> changing. This way the Location is never the same twice.
> Any suggestions appreciated.

I don't see why you need to use either with internal_redirect() - just pass
it the URI and let Apache handle it.  you would use a subrequest (initiated
from eather of the lookup functions) along with $sub->run() if you wanted to
send the contents of the subrequest along.

HTH

--Geoff


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


internal_redirect to randomly named filename

Posted by "dreamwvr@dreamwvr.com" <dr...@dreamwvr.com>.
Hi All,
  Since lookup_uri() is only to be used when the actual
URI physically exists. Having said that how does not tell 
it to pretend that a randomly generated virtual file exists?
Is that what lookup_filename() is for? I am wanting to do a 
internal_redirect() to a virtual file whose name is always
changing. This way the Location is never the same twice.
Any suggestions appreciated.

TIA
Best Regards,
dreamwvr@dreamwvr.com 
     
-- 
/*  Security is a work in progress - dreamwvr                 */
#                               48 69 65 72 6F 70 68 61 6E 74 32
# Note: To begin Journey type man afterboot,man help,man hier[.]      
# 66 6F 72 20 48 69 72 65                              0000 0001
// "Who's Afraid of Schrodinger's Cat?" /var/(.)?mail/me \?  ;-]

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Apache::Request vs Apache->request

Posted by Stas Bekman <st...@stason.org>.
Clayton Cottingham wrote:
> thanks for the reply 
> 
> here is something strange. i cant figure out based on all this, under mod perl 1 Apache/1.3.29 on FreeBSD devserver.ppw 5.1-RELEASE
> 
> below is a small piece of my module the 'parsefile' subroutine *does not* print out %args, i dont understand why not
> can someone explain?

yup, see below

> ************
> sub handler {
>     my $r = Apache->request;
> 
>    #for upload 
>     my $apr = Apache::Request->new(
>         $r,
>         POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
>         DISABLE_UPLOADS => 0
>     );
> 
> #if upload object exists
>     if ( $apr->upload ) {
>         parseFile($r);
>     }
>     else {
> 	#print form for upload
>         printForm($r);
>     }
> 
> }
> 
> sub parseFile {
>    my $r   = shift;
>    my $apr = Apache::Request->new(
>         $r,
>         POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
>         DISABLE_UPLOADS => 0
>     ) ;
>     my %args = $r->args;

of course, you create a new A::R object, you should use ->instance instead. Or 
even better pass $apr to parseFile, you don't need $r any longer, since $apr 
already $r and more.

__________________________________________________________________
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

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Apache::Request vs Apache->request

Posted by Clayton Cottingham <dr...@telus.net>.
thanks for the reply 

here is something strange. i cant figure out based on all this, under mod perl 1 Apache/1.3.29 on FreeBSD devserver.ppw 5.1-RELEASE

below is a small piece of my module the 'parsefile' subroutine *does not* print out %args, i dont understand why not
can someone explain?

************
sub handler {
    my $r = Apache->request;

   #for upload 
    my $apr = Apache::Request->new(
        $r,
        POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
        DISABLE_UPLOADS => 0
    );

#if upload object exists
    if ( $apr->upload ) {
        parseFile($r);
    }
    else {
	#print form for upload
        printForm($r);
    }

}

sub parseFile {
   my $r   = shift;
   my $apr = Apache::Request->new(
        $r,
        POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
        DISABLE_UPLOADS => 0
    ) ;
    my %args = $r->args;

 warn Data::Dumper::Dumper(%args);

#do stuff with $apr-upload such as store file

}

sub printForm {
    my $r = shift;

    $r->send_http_header('text/html');

    $r->print("<html><body>\n");
    $r->print("<h1>Upload sites</h1>");

    # Output a simple form.
    $r->print(<<EOF);
  <form enctype="multipart/form-data" name="files" action="/PP/excelupload" method="POST">
    Excel File <input type="file" name="file1"><br>
    <input type="submit" name="submit" value="Upload these files">
  </form>
 </body></html>
EOF

    return OK;
}
1;
**********


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Apache::Request vs Apache->request

Posted by Stas Bekman <st...@stason.org>.
Clayton Cottingham wrote:
> while i understand the difference between these two i am unsure how to
> handle these back and forth. let me explain:

There are not the same thing.

> I have an upload module with the handler using an Apache::Request
>    my $r = Apache::Request->new(
>         shift,
>         POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
>         DISABLE_UPLOADS => 0
>     );

Here $r is a subclass of Apache, so you can do operations as before and plus 
new A::R methods.

> later on i want to send all the info recieved from a file to another
> module that inserts this information into a database table
> 
> rather than pass through a  LWP::Simple::get call i would like to call
> the  subroutine that handles the logic directly like so:
> 
> &MYMod::Add::Add($r);
> 
> BUT i have the above subroutine pulling in the Apache->request object if
> through MYMod::Add::handler
> 
> 
> so i tried something like this in my upload module
> 
> 
>  my $r = Apache->request;

this is a plain $r.

>     # Standard stuff, with added options...
>     my $apr = Apache::Request->new(
>         $r,
>         POST_MAX        => 10 * 1024 * 1024,    # in bytes, so 10M
>         DISABLE_UPLOADS => 0
>     );

$apr is a subclassed object that know to do more than $r.

> and then 
> &MYMod::Add::Add($r);
> 
> but this just borks out the uplaod procedure
 >
> and nothing get processed, whereas if i just pass in the Apache::Request
> it doesnt process the parameters correctly

so you need to pass $apr. $r is still an Apache object, not an Apache::Request 
one. Apache::Request->new() doesn't affect $r in your code above.

__________________________________________________________________
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


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html