Internal redirect inside an input filter
Internal redirect inside an input filter
am 09.10.2008 14:30:47 von Dan DeSmet
------=_Part_107710_7967240.1223555447418
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
I'm attempting to write an input filter that performs an internal redirect
based on the contents of the cookies sent in the request headers. The
problem I'm encountering is that the browser is receiving both the content
for the original request, as well as the content generated by the internal
redirect. Ideally, the browser would receive only the content generated
from the internal redirect. Here is a sample filter I wrote while trying to
solve this problem:
package Test::Redirect;
# a bunch of use statements
sub handler : FilterRequestHandler {
my $f = shift;
# this is just any old uri
$f->r->internal_redirect('/reverse');
return Apache2::Const::OK;
}
I've tried setting the filter's context to allow it to run only once, but if
I do that, it never completes the request. Any ideas?
Thanks,
Dan
------=_Part_107710_7967240.1223555447418
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
I'm attempting to write an input filter that performs an internal redirect based on the contents of the cookies sent in the request headers. The problem I'm encountering is that the browser is receiving both the content for the original request, as well as the content generated by the internal redirect. Ideally, the browser would receive only the content generated from the internal redirect. Here is a sample filter I wrote while trying to solve this problem:
package Test::Redirect;
# a bunch of use statements
sub handler : FilterRequestHandler {
my $f = shift;
# this is just any old uri
$f->r->internal_redirect('/reverse');
return Apache2::Const::OK;
}
I've tried setting the filter's context to allow it to run only once, but if I do that, it never completes the request. Any ideas?
Thanks,
Dan
------=_Part_107710_7967240.1223555447418--
Re: Internal redirect inside an input filter
am 09.10.2008 14:50:48 von torsten.foertsch
On Thu 09 Oct 2008, Dan DeSmet wrote:
> I'm attempting to write an input filter that performs an internal
> redirect based on the contents of the cookies sent in the request
> headers.
Why an input filter? What you want is better done in a PerlTransHandler
or a PerlFixupHandler.
Torsten
--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net
Re: Internal redirect inside an input filter
am 09.10.2008 15:33:30 von Dan DeSmet
------=_Part_108178_4425962.1223559210459
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
I took your advice and tried switching it over to a TransHandler. Now, the
beginning of the handler where I manipulate the cookies looks like this:
sub handler {
my $r = shift;
my $cookieString = $r->headers_in->get('Cookie');
...
}
I then do a check to see if the cookies exist; that tells me whether it's a
client's first request, or a subsequent one. I then need to read a bunch of
information out of the cookies and then rewrite one of them. Unfortunately,
the above code always yields me an empty string. I can check my browser
cookies and see that they've been set correctly. Can the TransHandler
manipulate the request headers apart from the URI? Or am I just missing
something?
Thanks,
Dan
On Thu, Oct 9, 2008 at 8:50 AM, Torsten Foertsch
wrote:
> On Thu 09 Oct 2008, Dan DeSmet wrote:
> > I'm attempting to write an input filter that performs an internal
> > redirect based on the contents of the cookies sent in the request
> > headers.
>
> Why an input filter? What you want is better done in a PerlTransHandler
> or a PerlFixupHandler.
>
> Torsten
>
> --
> Need professional mod_perl support?
> Just hire me: torsten.foertsch@gmx.net
>
------=_Part_108178_4425962.1223559210459
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
I took your advice and tried switching it over to a TransHandler. Now, the beginning of the handler where I manipulate the cookies looks like this:
sub handler {
my $r = shift;
my $cookieString = $r->headers_in->get('Cookie');
...
}
I then do a check to see if the cookies exist; that tells me whether it's a client's first request, or a subsequent one. I then need to read a bunch of information out of the cookies and then rewrite one of them. Unfortunately, the above code always yields me an empty string. I can check my browser cookies and see that they've been set correctly. Can the TransHandler manipulate the request headers apart from the URI? Or am I just missing something?
Thanks,
Dan
On Thu, Oct 9, 2008 at 8:50 AM, Torsten Foertsch
<> wrote:
On Thu 09 Oct 2008, Dan DeSmet wrote:
> I'm attempting to write an input filter that performs an internal
> redirect based on the contents of the cookies sent in the request
> headers.
Why an input filter? What you want is better done in a PerlTransHandler
or a PerlFixupHandler.
Torsten
--
Need professional mod_perl support?
Just hire me:
------=_Part_108178_4425962.1223559210459--
Re: Internal redirect inside an input filter
am 09.10.2008 16:07:08 von torsten.foertsch
On Thu 09 Oct 2008, Dan DeSmet wrote:
> I took your advice and tried switching it over to a TransHandler.
> =A0Now, the beginning of the handler where I manipulate the cookies
> looks like this:
>
> sub handler {
> =A0 =A0 my $r =3D shift;
> =A0 =A0 my $cookieString =3D $r->headers_in->get('Cookie');
> =A0 =A0 ...
> }
>
> I then do a check to see if the cookies exist; that tells me whether
> it's a client's first request, or a subsequent one. =A0I then need to
> read a bunch of information out of the cookies and then rewrite one
> of them. =A0Unfortunately, the above code always yields me an empty
> string. =A0I can check my browser cookies and see that they've been set
> correctly. =A0Can the TransHandler manipulate the request headers apart
> from the URI? =A0Or am I just missing something?
I have just checked it using the following TransHandler (directly=20
implemented in the httpd.conf):
PerlTransHandler "sub { \
my ($r)=3D@_; \
warn qq{Got Cookie: }.$r->headers_in->{Cookie}; \
return Apache2::Const::DECLINED; \
}"
Now, I call:
curl -v http://localhost
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.18.1 (x86_64-suse-linux-gnu) libcurl/7.18.1=20
OpenSSL/0.9.8g zlib/1.2.3 libidn/1.8
> Host: localhost
> Accept: */*
..
No cookie is transmitted and in the error_log appears the line:
Got Cookie: at (eval 91) line 1.
But if I call this:
curl -v -b 'klaus=3Dotto' http://localhost
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.18.1 (x86_64-suse-linux-gnu) libcurl/7.18.1=20
OpenSSL/0.9.8g zlib/1.2.3 libidn/1.8
> Host: localhost
> Accept: */*
> Cookie: klaus=3Dotto
..
You see the cookie-header? In the error_log I see:
Got Cookie: klaus=3Dotto at (eval 91) line 1.
So, yes, you can manipulate request headers in the translation phase. In=20
fact, they are already accessible even in a PerlPostReadRequestHandler=20
which comes before the PerlTransHandler and is the very first occasion=20
when a Perl module can interfere. The main difference between=20
postreadrequest and translation is that the former is skipped for=20
subrequests and internal redirects. You can try my little handler as=20
PerlPostReadRequestHandler and will see the same result.
Torsten
=2D-
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net
Re: Internal redirect inside an input filter
am 09.10.2008 16:54:59 von Dan DeSmet
------=_Part_109482_17800008.1223564099592
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Thanks for your help. Your confirmation led me to track down the real
problem, which is that I marked the cookies secure, and forgot to do https
rather than http in my browser URL. If not for your help, there's no
telling how long I would've spent trying to fix a problem in my code that
didn't exist.
Thanks.
On Thu, Oct 9, 2008 at 10:07 AM, Torsten Foertsch
wrote:
> On Thu 09 Oct 2008, Dan DeSmet wrote:
> > I took your advice and tried switching it over to a TransHandler.
> > Now, the beginning of the handler where I manipulate the cookies
> > looks like this:
> >
> > sub handler {
> > my $r = shift;
> > my $cookieString = $r->headers_in->get('Cookie');
> > ...
> > }
> >
> > I then do a check to see if the cookies exist; that tells me whether
> > it's a client's first request, or a subsequent one. I then need to
> > read a bunch of information out of the cookies and then rewrite one
> > of them. Unfortunately, the above code always yields me an empty
> > string. I can check my browser cookies and see that they've been set
> > correctly. Can the TransHandler manipulate the request headers apart
> > from the URI? Or am I just missing something?
>
> I have just checked it using the following TransHandler (directly
> implemented in the httpd.conf):
>
> PerlTransHandler "sub { \
> my ($r)=@_; \
> warn qq{Got Cookie: }.$r->headers_in->{Cookie}; \
> return Apache2::Const::DECLINED; \
> }"
>
> Now, I call:
>
> curl -v http://localhost
> * About to connect() to localhost port 80 (#0)
> * Trying 127.0.0.1... connected
> * Connected to localhost (127.0.0.1) port 80 (#0)
> > GET / HTTP/1.1
> > User-Agent: curl/7.18.1 (x86_64-suse-linux-gnu) libcurl/7.18.1
> OpenSSL/0.9.8g zlib/1.2.3 libidn/1.8
> > Host: localhost
> > Accept: */*
> ...
>
> No cookie is transmitted and in the error_log appears the line:
>
> Got Cookie: at (eval 91) line 1.
>
> But if I call this:
>
> curl -v -b 'klaus=otto' http://localhost
> * About to connect() to localhost port 80 (#0)
> * Trying 127.0.0.1... connected
> * Connected to localhost (127.0.0.1) port 80 (#0)
> > GET / HTTP/1.1
> > User-Agent: curl/7.18.1 (x86_64-suse-linux-gnu) libcurl/7.18.1
> OpenSSL/0.9.8g zlib/1.2.3 libidn/1.8
> > Host: localhost
> > Accept: */*
> > Cookie: klaus=otto
> ...
>
> You see the cookie-header? In the error_log I see:
>
> Got Cookie: klaus=otto at (eval 91) line 1.
>
> So, yes, you can manipulate request headers in the translation phase. In
> fact, they are already accessible even in a PerlPostReadRequestHandler
> which comes before the PerlTransHandler and is the very first occasion
> when a Perl module can interfere. The main difference between
> postreadrequest and translation is that the former is skipped for
> subrequests and internal redirects. You can try my little handler as
> PerlPostReadRequestHandler and will see the same result.
>
> Torsten
>
> --
> Need professional mod_perl support?
> Just hire me: torsten.foertsch@gmx.net
>
------=_Part_109482_17800008.1223564099592
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Thanks for your help. Your confirmation led me to track down the real problem, which is that I marked the cookies secure, and forgot to do https rather than http in my browser URL. If not for your help, there's no telling how long I would've spent trying to fix a problem in my code that didn't exist.
Thanks.
On Thu, Oct 9, 2008 at 10:07 AM, Torsten Foertsch
<> wrote:
On Thu 09 Oct 2008, Dan DeSmet wrote:
> I took your advice and tried switching it over to a TransHandler.
> Now, the beginning of the handler where I manipulate the cookies
> looks like this:
>
> sub handler {
> my $r = shift;
> my $cookieString = $r->headers_in->get('Cookie');
> ...
> }
>
> I then do a check to see if the cookies exist; that tells me whether
> it's a client's first request, or a subsequent one. I then need to
> read a bunch of information out of the cookies and then rewrite one
> of them. Unfortunately, the above code always yields me an empty
> string. I can check my browser cookies and see that they've been set
> correctly. Can the TransHandler manipulate the request headers apart
> from the URI? Or am I just missing something?
I have just checked it using the following TransHandler (directly
implemented in the httpd.conf):
PerlTransHandler "sub { \
my ($r)=@_; \
warn qq{Got Cookie: }.$r->headers_in->{Cookie}; \
return Apache2::Const::DECLINED; \
}"
Now, I call:
curl -v
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1... connected
* Connected to localhost () port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.18.1 (x86_64-suse-linux-gnu) libcurl/7.18.1
OpenSSL/0.9.8g zlib/1.2.3 libidn/1.8
> Host: localhost
> Accept: */*
....
No cookie is transmitted and in the error_log appears the line:
Got Cookie: at (eval 91) line 1.
But if I call this:
curl -v -b 'klaus=otto'
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1... connected
* Connected to localhost () port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.18.1 (x86_64-suse-linux-gnu) libcurl/7.18.1
OpenSSL/0.9.8g zlib/1.2.3 libidn/1.8
> Host: localhost
> Accept: */*
> Cookie: klaus=otto
....
You see the cookie-header? In the error_log I see:
Got Cookie: klaus=otto at (eval 91) line 1.
So, yes, you can manipulate request headers in the translation phase. In
fact, they are already accessible even in a PerlPostReadRequestHandler
which comes before the PerlTransHandler and is the very first occasion
when a Perl module can interfere. The main difference between
postreadrequest and translation is that the former is skipped for
subrequests and internal redirects. You can try my little handler as
PerlPostReadRequestHandler and will see the same result.
Torsten
--
Need professional mod_perl support?
Just hire me:
------=_Part_109482_17800008.1223564099592--