You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Zsolt Czinkos <cz...@interware.hu> on 2002/01/08 14:40:06 UTC
Beginner's FixupHandler question
Hello everyone
I've just started learning modperl and I started with a simple module
for apache httpd 1.3.22.
This simple module (see below) sets & gets a cookie at every request.
I thought it wasn't too difficult. I put it into the fixup phase (any
problem with it?).
First it seemed to work, but when I put a 'print STDERR' line in it, I
saw that my script ran many times on one request.
Thanks in advance
czinkos
ps: I've searched the archives but I didn't find anything.
--------
Here's my config in httpd.conf
...
PerlFreshRestart On
PerlModule SetMyCookies
PerlFixupHandler SetMyCookies
...
-------
Here's my simple script:
package SetMyCookies;
use Apache;
use Apache::Constants;
use Apache::Cookie();
sub handler {
my $r = shift;
$c = $r->header_in("Cookie");
local(@rawCookies) = split (/; /,$c);
local(%cookies);
foreach(@rawCookies){
($key, $val) = split (/=/,$_);
$cookies{$key} = $val;
}
foreach $name (keys %cookies) {
print STDERR "$name = $cookies{$name}\n";
}
my $cookie = Apache::Cookie->new($r,
-name => 'lofos',
-value => 'lofos13',
-expires=> '+24M',
-path => '/'
);
$r->header_out("Set-Cookie",$cookie->as_string);
return OK;
}
1;
---------------
And here's the error_log on one request:
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
kakukk = kukka234534
Re: Beginner's FixupHandler question
Posted by Robert Landrum <rl...@capitoladvantage.com>.
At 2:40 PM +0100 1/8/02, Zsolt Czinkos wrote:
>
>-------
>Here's my simple script:
>
>package SetMyCookies;
>
>use Apache;
>use Apache::Constants;
>use Apache::Cookie();
Very important to use strict when writing anything in mod_perl.
>sub handler {
>
>my $r = shift;
>
> $c = $r->header_in("Cookie");
$c is going to persist across multiple connections without my().
> local(@rawCookies) = split (/; /,$c);
> local(%cookies);
Use my()... my() is more appropriate in this case.
Always reset %cookies = (); # just in case
> foreach(@rawCookies){
> ($key, $val) = split (/=/,$_);
> $cookies{$key} = $val;
> }
>
be sure to my() $key and $val
> foreach $name (keys %cookies) {
> print STDERR "$name = $cookies{$name}\n";
> }
My() $name.
> my $cookie = Apache::Cookie->new($r,
> -name => 'lofos',
> -value => 'lofos13',
> -expires=> '+24M',
> -path => '/'
> );
>
> $r->header_out("Set-Cookie",$cookie->as_string);
>
> return OK;
>}
>1;
>
>---------------
>And here's the error_log on one request:
More importantly, check your access log. Something like a nimda in
association with the above code might produce multiple lines in your
error log like this.
>kakukk = kukka234534
>kakukk = kukka234534
>kakukk = kukka234534
>kakukk = kukka234534
Good luck,
Rob
--
When I used a Mac, they laughed because I had no command prompt. When
I used Linux, they laughed because I had no GUI.
Re: Beginner's FixupHandler question
Posted by Paul Lindner <li...@inuus.com>.
On Tue, Jan 08, 2002 at 10:07:18AM -0600, Stathy G. Touloumis wrote:
>
> >I've just started learning modperl and I started with a simple module
> >for apache httpd 1.3.22.
> >This simple module (see below) sets & gets a cookie at every request.
> >I thought it wasn't too difficult. I put it into the fixup phase (any
> >problem with it?).
> >First it seemed to work, but when I put a 'print STDERR' line in it, I
> >saw that my script ran many times on one request.
>
> What is your interpretation of 'one' request? Remember, when requesting a
> url there may be 'many' requests that go along with it for loading images
> and other media.
>
> If you don't want to set/get cookie for every request try filtering based
> on $r->content_type. But, your handler will still be called for every
> request : )
Apache provides configuration tools that can help. PerlFixupHandlers
can be placed within a <Location> or <LocationMatch> container. For
example:
<LocationMatch "^/myapp/.*html$">
will insure that your fixup handler is only called on requests that
start with "/myaap/" and end with ".html".
--
Paul Lindner lindner@inuus.com ||||| | | | | | | | | |
mod_perl Developer's Cookbook http://www.modperlcookbook.org
Human Rights Declaration http://www.unhchr.ch/udhr/index.htm
Re: Beginner's FixupHandler question
Posted by Zsolt Czinkos <cz...@interware.hu>.
My One request is:
[czinkos@vajradhara apache]$ telnet localhost 8080
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0
Cookie: pritty=prutty
It is only 1 html source.
Thanks
czinkos
On Tue, Jan 08, 2002 at 10:07:18AM -0600, Stathy G. Touloumis wrote:
>
> >I've just started learning modperl and I started with a simple module
> >for apache httpd 1.3.22.
> >This simple module (see below) sets & gets a cookie at every request.
> >I thought it wasn't too difficult. I put it into the fixup phase (any
> >problem with it?).
> >First it seemed to work, but when I put a 'print STDERR' line in it, I
> >saw that my script ran many times on one request.
>
> What is your interpretation of 'one' request? Remember, when requesting a
> url there may be 'many' requests that go along with it for loading images
> and other media.
>
> If you don't want to set/get cookie for every request try filtering based
> on $r->content_type. But, your handler will still be called for every
> request : )
>
>
> -- There is always somebody better than you . . .
> -- Until you realize this you can never be the best.
>
> Stathy G. Touloumis
> Coder
Re: Beginner's FixupHandler question
Posted by "Stathy G. Touloumis" <st...@stathy.com>.
>I've just started learning modperl and I started with a simple module
>for apache httpd 1.3.22.
>This simple module (see below) sets & gets a cookie at every request.
>I thought it wasn't too difficult. I put it into the fixup phase (any
>problem with it?).
>First it seemed to work, but when I put a 'print STDERR' line in it, I
>saw that my script ran many times on one request.
What is your interpretation of 'one' request? Remember, when requesting a
url there may be 'many' requests that go along with it for loading images
and other media.
If you don't want to set/get cookie for every request try filtering based
on $r->content_type. But, your handler will still be called for every
request : )
-- There is always somebody better than you . . .
-- Until you realize this you can never be the best.
Stathy G. Touloumis
Coder