Can't retrieve form params using post methods, $r-notes and Apache::Request
Hi all, I have the following configuration. Location /my SetHandler perl-script PerlAccessHandler MyCheck PerlHandler MyHomePage /Location The PerlAccessHandler checks if the user cookie is valid and set a $r-notes() entry to pass the user id to the MyHomePage handler which do his work. In the MyHomePage hanlder i'm using Apache::Request (my $apr = new Apache::Request($r); ) to get the parameters of the form from which i'm calling the handler. If i put the form method in POST, I can't get any parameters, the form is reloaded, but if i put the method to GET then everything is fine. If I use the following configuration Location /my SetHandler perl-script PerlHandler MyHomePage /Location and use either the POST or GET for the form everything is fine. If I put a PerlAccessHandler not using the $r-notes() method then everything is fine. So my problem must come from the $r-notes(). Apparently it messes up with the POST parameters. Does somebody have an idea why it doesn't work with the POST method ? I've lost quite a lot of time with that, even if it works with the GET i'd like to understand. Regards, Mat ps: OS: Linux 2.4.14 Apache 1.3.20 mod_perl 1.26 perl 5.6.1
Re: Can't retrieve form params using post methods, $r-notes and Apache::Request
Mat wrote: Hi all, I have the following configuration. Location /my SetHandler perl-script PerlAccessHandler MyCheck PerlHandler MyHomePage /Location The PerlAccessHandler checks if the user cookie is valid and set a $r-notes() entry to pass the user id to the MyHomePage handler which do his work. In the MyHomePage hanlder i'm using Apache::Request (my $apr = new Apache::Request($r); ) to get the parameters of the form from which i'm calling the handler. If i put the form method in POST, I can't get any parameters, the form is reloaded, but if i put the method to GET then everything is fine. If I use the following configuration Location /my SetHandler perl-script PerlHandler MyHomePage /Location and use either the POST or GET for the form everything is fine. If I put a PerlAccessHandler not using the $r-notes() method then everything is fine. So my problem must come from the $r-notes(). Apparently it messes up with the POST parameters. That seems pretty unlikely. Are you sure you're not trying to read the POST content twice? Maybe you're using a module that reads it? - Perrin
Re: maximum (practical) size of $r-notes
In continuing my work on this template system, I've run into another problem. Any one or more of the components can be a script, and the problem with the existing system which I'm trying to solve is catching redirects by them. The order in which I'm doing things is now: ( 4 part handler ) Part 1: Get the template set id (int), title, and meta designations from the requested file. Put this list in pnotes. Part 2: Add to that list the header, footer, toolbar, and content files as as designated in the template file. Part 3: Run through the list of components, and execute anything that needs to be executed. Capture the output and put it in pnotes. Part 4: Check for redirects, and send one if it exists. If not, print the template filled in with the output from the list entries. I had previously been executing component scripts like this: ($file is an entry in the list from Parts 12. All entries in that list are full pathnames. $args is a list of parameters set up previously in the handler.) if ( -x $file ) { $file =~ s/\/www\/html//o; $file = $file .'?'.$args if $args; my $subr = $r-lookup_uri($file); $subr-handler('cgi-script'); $subr-run(); return; } This doesn't work especially well anymore, as $subr-run outputs to the browser. I've looked through past list messages, and from what I've read there's no way to suppress that. Is there a reason that no one has come up with a method for doing this? It seems like a few people have asked about it, are we all going about things the wrong way? I'm not a C guy, so I'd probably need a little guidance, but I'd be happy to work a patch if no else wants to. Barring that, what's the best way to do what I need to do? exec'ing (and it's cousins) the scripts doesn't sound pretty, but I'm at a loss on what else to try. thanks, Todd At 12:29 AM 10/30/00, Todd Finney wrote: This is a follow-up on a question that I asked a couple of months ago. The subject was "executing a cgi from within a handler (templating redux)", dated 8/23/00. The gist of the matter is that we need a handler which will serve html pages ('content files') inside of other html files ('template files'), while sticking other files and scripts ('component files') into the template at the same time. Quasi-frames, if you will. We've already covered why we didn't pick one of the readily-available packages to do this. We've had a working handler that does _almost_everything it needs to do. When the user requests a page, it figures out which template to use (based on the page requested), which component set to use (based on the user and the page), rolls the whole thing together and sends it along. The wrapper can handle both static files and scripts as components or content files, and works really well most of the time. However, we've run into a problem when a page needs to redirect after execution, such as a login page. The problem is that when a component or content file is a script, the server executes that script when it encounters it in the template, a'la - hey, the user wants foo.html - the user is a member of group 'coders', and their component path is /www/htdocs/components/coders/ - foo.html wants template set 1, - go get /www/htdocs/components/coders/tmpl_1, and open - begin printing the template file to the browser. As the file goes by, watch for [tags] containing insertion points. - hey, there's [head], print or execute /www/htdocs/components/coders/head_1 - hey, there's [tool], print or execute /www/htdocs/components/coders/tool_1 - hey, there's [cont], print or execute foo.html - hey, there's [foot], print or execute /www/htdocs/components/coders/foot_1 - finish printing /www/htdocs/components/coders/tmpl_1 and close If /www/htdocs/components/coders/tool_1 has a redirect call in it, it's too late for the browser to actually do anything about it. I managed to corner Nathan in New York (thanks, Nathan!). He recommended a two-stage handler, one that processes the components and content, and another that actually handles the printing. Using $r-notes, the second handler could be aware of what it needed to do before printing anything. This is a really good idea, but it's turning out to be more difficult than I anticipated. The only way I can think of doing this is adding a third handler, in the middle, that executes any scripts and stores the output somewhere. Then it would check the output for a Location: header and set something like $notes-{'redirect'} if it finds anything. The third handler would then check that value before printing anything. If it's there, do it; if not, grab the output and the static files and print them to the user. I'm concerned about putting large amounts of data into $r-notes. Some of our script output can be pretty heavy. If $r-notes can only take simple strings, how large of a simple string
Re: maximum (practical) size of $r-notes
On Mon, 30 Oct 2000, Matt Sergeant wrote: On Mon, 30 Oct 2000, Todd Finney wrote: I'm concerned about putting large amounts of data into $r-notes. Some of our script output can be pretty heavy. If $r-notes can only take simple strings, how large of a simple string is it safe to put in it? Is there a better way to do this? AxKit uses the notes table to store interim strings for template processing. I've not yet heard a bug related to it, but then I'm not delivering massive files. I'd imagine it would probably be limited by available memory. This is basically correct. The notes table is tied to Apache::Table, which in itself is an ap_table, (with C accessors of ap_table_get() and ap_table_set()). Like everything else in Apache, it is based on the pools system of memory management, which will quite happily allocate up to the amount of memory you have, and will then throw it away at the end of the request. However, apache itself calls malloc() but never calls free(), because once it has allocated the memory, it manages it itself. Given that the notes table is allocated from the request pool (such that it is thrown away at the end of a request). It will always happen in the child and can never be shared - so if you have large numbers of apache processes, then this might (if you're using a lot of memory) be able to take the machine down. But the memory management system in apache is only limited by the amount of memory that the system will let it allocate - which means that you should be OK. MBM -- Matthew Byng-Maddick Home: [EMAIL PROTECTED] +44 20 8981 8633 (Home) http://colondot.net/ Work: [EMAIL PROTECTED] +44 7956 613942 (Mobile) "It's today!" said Piglet. "My favourite day," said Pooh.
Re: maximum (practical) size of $r-notes
Hi all, On Mon, 30 Oct 2000, Matthew Byng-Maddick wrote: On Mon, 30 Oct 2000, Matt Sergeant wrote: On Mon, 30 Oct 2000, Todd Finney wrote: AxKit uses the notes table to store interim strings for template processing. I've not yet heard a bug related to it, but then I'm not delivering massive files. I'd imagine it would probably be limited by available memory. This is basically correct. The notes table is tied to Apache::Table, If it's a huge amount of data and you don't want to bloat your processes, why not pass a tempfile name/pointer/handle in $r-notes and write the data to a ramdisk? I wouldn't think you'd lose much in opening and closing the file. 73, Ged.
RE: maximum (practical) size of $r-notes
-Original Message- From: G.W. Haywood [mailto:[EMAIL PROTECTED]] Sent: Monday, October 30, 2000 7:29 AM To: Matthew Byng-Maddick Cc: [EMAIL PROTECTED] Subject: Re: maximum (practical) size of $r-notes Hi all, On Mon, 30 Oct 2000, Matthew Byng-Maddick wrote: On Mon, 30 Oct 2000, Matt Sergeant wrote: On Mon, 30 Oct 2000, Todd Finney wrote: AxKit uses the notes table to store interim strings for template processing. I've not yet heard a bug related to it, but then I'm not delivering massive files. I'd imagine it would probably be limited by available memory. This is basically correct. The notes table is tied to Apache::Table, If it's a huge amount of data and you don't want to bloat your processes, why not pass a tempfile name/pointer/handle in $r-notes and write the data to a ramdisk? I wouldn't think you'd lose much in opening and closing the file. or (easier) just place a reference to a variable containing your data in pnotes instead of notes - that way a reference, and not the data, is passed around. the data has to exist somewhere, but now you only have one copy of it... pnotes is (IMHO) the single greatest, but least well known method in mod_perl - don't leave home without it... --Geoff 73, Ged.
RE: maximum (practical) size of $r-notes
-Original Message- From: G.W. Haywood [mailto:[EMAIL PROTECTED]] Sent: Monday, October 30, 2000 10:06 AM To: Geoffrey Young Cc: [EMAIL PROTECTED] Subject: RE: maximum (practical) size of $r-notes Hi all, On Mon, 30 Oct 2000, Geoffrey Young wrote: From: G.W. Haywood [mailto:[EMAIL PROTECTED]] If it's a huge amount of data and you don't want to bloat your processes, why not pass a tempfile name/pointer/handle in $r-notes or (easier) just place a reference to a variable containing your data in pnotes instead of notes - that way a reference, and not the data, is passed around. the data has to exist somewhere, but now you only have one copy of it... If the data is in a Perl variable somewhere Perl will already have grabbed enough memory to store it. Won't Perl then just keep that memory until the child dies, even if you undef the variable containing the data? that is my understanding... I guess that my point was that if you are going to have the data in perl somewhere the memory is going to be taken (for example, putting it in a tempfile but then local $/ and slurp). pnotes allows for passing by reference, so it really doesn't matter when you read it in and where you use it, you still only have one copy... but then again, it's monday morning and my coffee was weak today... My idea was to avoid this cause of process bloat. If the data isn't in a Perl data structure is this always safe? I dunno --Geoff 73, Ged.
RE: maximum (practical) size of $r-notes
On Mon, 30 Oct 2000, Geoffrey Young wrote: that is my understanding... I guess that my point was that if you are going to have the data in perl somewhere the memory is going to be taken (for example, putting it in a tempfile but then local $/ and slurp). pnotes allows for passing by reference, so it really doesn't matter when you read it in and where you use it, you still only have one copy... Of course there's no functional difference between using pnotes and something like: $Apache::Pnotes::myvar = \$string; Its really just syntactic sugar to make you think that its a notes table for a perl data structure. -- Matt/ /||** Director and CTO ** //||** AxKit.com Ltd ** ** XML Application Serving ** // ||** http://axkit.org ** ** XSLT, XPathScript, XSP ** // \\| // ** Personal Web Site: http://sergeant.org/ ** \\// //\\ // \\
RE: maximum (practical) size of $r-notes
Hi Geoff, On Mon, 30 Oct 2000, Geoffrey Young wrote: Ged mumbled: Won't Perl then just keep that memory until the child dies...? that is my understanding... I guess that my point was that if you are going to have the data in perl somewhere the memory is going to be taken (for example, putting it in a tempfile but then local $/ and slurp). Right. I think people are much too fond of slurping in whole files in that way. It's OK in development, then some villain sends you tewnty megabytes instead of twenty bytes. Clang. It's a little more work to break things up into some smaller pieces but you can gain a lot in efficiency sometimes. 73, Ged.
Re: $r-notes with slashes
On Mon, 14 Aug 2000, Andrew Fuqua wrote: I'm trying to pass a path name with slashes as the value of a note, and when I try to retrieve the note from another handler in the same request, the note is not there. Code goes like this: in a PerlInitHandler: $r-notes('dir_name' = '/some/dir/name/'); later, in a PerlAuthzHandler: my $dir_name = $r-notes('dir_name'); and $dir_name is empty. :( I can set and retrieve the note just fine as long as there are no slashes in the note. works fine for me with this test case: Location / PerlInitHandler 'sub { shift-notes(dir_name = "/some/dir/name/") }' require valid-user AuthType basic AuthName test PerlAuthenHandler Apache::OK PerlAuthzHandler 'sub { Apache::OK if shift-notes("dir_name") }' /Location you'll only get prompted for user/pass if dir_name is not found in the notes table, does it work for you? Another question. From a handler, how can I change the value of a variable that was PerlSetVar'ed in httpd.conf? as geoff explained, you can, but the value might stick for that child if the SetVar was configured in httpd.conf. so you might want to reset it: my $old_val = $r-dir_config-get('foo'); $r-register_cleanup(sub { shift-dir_config-set(foo = $old_val) }); $r-dir_config-set(foo = $new_val);
$r-notes with slashes
I'm trying to pass a path name with slashes as the value of a note, and when I try to retrieve the note from another handler in the same request, the note is not there. Code goes like this: in a PerlInitHandler: $r-notes('dir_name' = '/some/dir/name/'); later, in a PerlAuthzHandler: my $dir_name = $r-notes('dir_name'); and $dir_name is empty. :( I can set and retrieve the note just fine as long as there are no slashes in the note. Another question. From a handler, how can I change the value of a variable that was PerlSetVar'ed in httpd.conf? Thanks, Andrew
RE: $r-notes with slashes
-Original Message- From: Andrew Fuqua [mailto:[EMAIL PROTECTED]] Sent: Monday, August 14, 2000 12:44 PM To: [EMAIL PROTECTED] Subject: $r-notes with slashes I'm trying to pass a path name with slashes as the value of a note, and when I try to retrieve the note from another handler in the same request, the note is not there. Code goes like this: in a PerlInitHandler: $r-notes('dir_name' = '/some/dir/name/'); later, in a PerlAuthzHandler: my $dir_name = $r-notes('dir_name'); and $dir_name is empty. :( I can set and retrieve the note just fine as long as there are no slashes in the note. try pnotes: $r-pnotes(dir_name = $some_string); or $r-pnotes(dir_name = \$some_string); Another question. From a handler, how can I change the value of a variable that was PerlSetVar'ed in httpd.conf? you can use Apache::Table to get or set things in PerlSetVar: $r-dir_config-get('foo'); $r-dir_config-set(foo = 'changed'); I haven't changed PerlSetVar like this, but a quick test showed that it worked ok... I've noticed that the Apache::Table way only works for PerlSetVar things on a per-directory basis - it doesn't seem to inherit per-server variables properly at this time... HTH --Geoff Thanks, Andrew
Re: $r-notes with slashes
Geoffrey Young wrote: -Original Message- From: Andrew Fuqua [mailto:[EMAIL PROTECTED]] Sent: Monday, August 14, 2000 12:44 PM To: [EMAIL PROTECTED] Subject: $r-notes with slashes I'm trying to pass a path name with slashes as the value of a note, and when I try to retrieve the note from another handler in the same request, the note is not there. Code goes like this: in a PerlInitHandler: $r-notes('dir_name' = '/some/dir/name/'); later, in a PerlAuthzHandler: my $dir_name = $r-notes('dir_name'); and $dir_name is empty. :( I can set and retrieve the note just fine as long as there are no slashes in the note. try pnotes: $r-pnotes(dir_name = $some_string); or $r-pnotes(dir_name = \$some_string); If that works, then $r-notes is broken and needs to be fixed. My guess is that it would be an Apache problem, not a mod_perl specific one.
$r-notes()...
If I use $r-notes in a mod_perl handler, is it accessible via the core apache request object in other non-perl modules? $r-notes('foo','bar'); Is the value of notes stored in the core apache process and if so, is it accessible by other modules by their similar r-notes methods (ie, mod_java or some custom C module)? If not, why not? I wouldn't expect to be able to store hashes, etc (use a global var, such as $sitename::globalvar for that), but strings? My question being stemmed from the possibility of having to use mod_java and mod_perl on the same server and getting the two to talk to each other in a friendly manner. Anyone have any experience w/ this or tips w/ regards to the best way of going about this kind of a setup? -- Sean Chittenden [EMAIL PROTECTED] VMS, n: The world's foremost multi-user adventure game.
Re: $r-notes()...
[EMAIL PROTECTED] (Sean Chittenden) wrote: If I use $r-notes in a mod_perl handler, is it accessible via the core apache request object in other non-perl modules? $r-notes('foo','bar'); Yup, it's stored in the regular Apache notes table. That's why it has to be flattened to a string, so it can't store arbitrary data structures (without some work). I've never passed values to a non-Perl module myself, but it seems like one of the main purposes for $r-notes. ------ Ken Williams Last Bastion of Euclidity [EMAIL PROTECTED]The Math Forum
RE: $r-notes()...
Sean Chittenden wrote: If I use $r-notes in a mod_perl handler, is it accessible via the core apache request object in other non-perl modules? $r-notes('foo','bar'); Is the value of notes stored in the core apache process and if so, is it accessible by other modules by their similar r-notes methods (ie, mod_java or some custom C module)? If not, why not? I wouldn't expect to be able to store hashes, etc (use a global var, such as $sitename::globalvar for that), but strings? My question being stemmed from the possibility of having to use mod_java and mod_perl on the same server and getting the two to talk to each other in a friendly manner. Anyone have any experience w/ this or tips w/ regards to the best way of going about this kind of a setup? I've got this working. I'm passing notes between mod_pop3 and mod_perl, and it's really handy. First, I've got a mod_perl fixup handler that tosses some info in the environment which is later read by mod_pop3. (I could have done this with notes, but I chose env.) Then, the PHP application sometimes calls the mod_perl app, by marking up a bunch of notes in its own request and then issuing a sub-request to a mod_perl page. The mod_perl request handler that gets this internal sub-request reads those notes and writes its replies in the same place. I read setup this request with: if (isset($user) substr($user,0,1) == "+") { apache_note("imp_euser", substr($user,1)); virtual("/internal/getquota"); $quota = apache_note("imp_quota"); $quota_pp = apache_note("imp_quota_pp"); $usage_pp = apache_note("imp_usage_pp"); $percent_pp = apache_note("imp_percent_pp"); if ($quota) $message .= " | Using $percent_pp% of $quota_pp limit"; } and then read and write the notes with $r-main-notes from mod_perl. - David Harris Principal Engineer, DRH Internet Services