You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Beberle <be...@yahoo.com> on 2004/12/13 11:43:35 UTC
[mp2] how to redirect POST data
Hi,
I found a similar question posted in the newsgroups
but no one seemed to have a solution. Here's what I'm
trying to do. I have a web page that does a POST to a
remote server. Basiscally, I'm trying to read the
post data and if it matches a regex, I want to
redirect it. Otherwise, I want to let the POST
continue normally (submitting to the remote server).
At the PerlTransHandler stage, I have a handler that
reads the post data like so:
my $method = $r->method();
if ($method =~ /post/i) {
my $content;
$r->read($content,
$r->headers_in->{'content-length'});
if ($content =~ /some_regex/){
# redirect
} else {
# continue with post
return OK;
}
}
I can capture the POST data and redirect the user just
fine. The problem occurs with the submitted forms that
don't match the regex. If I just return OK, the
browser hangs (because the POST data has been reset?).
I'll admit I'm a bit confused as to what's actually
going on here (still new to mod_perl). I read you're
not supposed to parse the form data except at the
ContentHandler step, but since the form is submitting
to a remote host, I can't really do that.
Any ideaas?
Thanks,
Bill
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
Report problems: 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: [mp2] how to redirect POST data
Posted by Reenen C Kroukamp <re...@discovery.co.za>.
On Mon, Dec 13, 2004 at 01:02:42PM +0100, Tom Schindl wrote:
...
> > if ($content =~ /some_regex/){
> > # redirect
> > } else {
> > # continue with post
> > return OK;
> > }
> >}
...
> The problem with POSTED data is that you can not read them more than
> once you can think of it like STDIN when read once you can not go back
> and read it once more.
...
> In mp2 you could also use an input-filter for this purpose.
Or, if the rewrite rules are not dynamic, you could probably get away
with just using mod_rewrite. You can use RewriteCond %{HTTP_HOST} to
match on the some_regex, and RewriteRule to redirect or rewrite.
Some more info here:
http://httpd.apache.org/docs/mod/mod_rewrite.html
http://httpd.apache.org/docs-2.0/misc/rewriteguide.html
-R
--
Reenen C Kroukamp <re...@qualica.com>
Qualica Technologies (Pty) Ltd
http://www.qualica.com/
--
Report problems: 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: compile problems
Posted by Matthew Berk <ma...@local-i.com>.
Found a solution worth writing about. I went through the perl
configuration interactively, specifying the following non-defaults:
- compile perl as shared
- use gcc, not cc, as the compiler
- provide -fPIC to the compiler
After this, everything worked like a charm!
On Dec 17, 2004, at 2:05 AM, Matthew Berk wrote:
> Apologies if I'm posting in the wrong place, but here goes:
>
> AMD Opteron, Suse 9.1, perl 5.8.6, Apache 2.0.52, mod_perl 1.99_17
>
> Apache compiles fine. When compiling mod_perl, I execute
> "/usr/local/bin/perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs"
> and then make, and get:
>
> /usr/lib64/gcc-lib/x86_64-suse-linux/3.3.3/../../../../x86_64-suse-
> linux/bin/ld:
> /usr/local/lib/perl5/5.8.6/x86_64-linux/auto/DynaLoader/
> DynaLoader.a(DynaLoader.o): relocation R_X86_64_32 can not be used
> when making a shared object; recompile with -fPIC
> /usr/local/lib/perl5/5.8.6/x86_64-linux/auto/DynaLoader/DynaLoader.a:
> could not read symbols: Bad value
> collect2: ld returned 1 exit status
>
> A perl -V reveals:
>
> Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
> Platform:
> osname=linux, osvers=2.6.5-7.95-smp, archname=x86_64-linux
> uname='linux local03 2.6.5-7.95-smp #1 smp thu jul 1 15:23:45 utc
> 2004 x86_64 x86_64 x86_64 gnulinux '
> config_args='-des -Dcccdlflags=-fPIC'
> hint=previous, useposix=true, d_sigaction=define
> usethreads=undef use5005threads=undef useithreads=undef
> usemultiplicity=undef
> useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
> use64bitint=define use64bitall=define uselongdouble=undef
> usemymalloc=n, bincompat5005=undef
> Compiler:
> cc='cc', ccflags ='-fno-strict-aliasing -pipe -I/usr/local/include
> -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
> optimize='-O2',
> cppflags='-fno-strict-aliasing -pipe -I/usr/local/include
> -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE
> -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -pipe -I/usr/local/include
> -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
> ccversion='', gccversion='3.3.3 (SuSE Linux)', gccosandvers=''
> intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
> d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
> ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
> lseeksize=8
> alignbytes=8, prototype=define
> Linker and Libraries:
> ld='cc', ldflags =' -L/usr/local/lib'
> libpth=/usr/local/lib /lib /usr/lib
> libs=-lnsl -ldl -lm -lcrypt -lutil -lc
> perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
> libc=, so=so, useshrplib=false, libperl=libperl.a
> gnulibc_version='2.3.3'
> Dynamic Linking:
> dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
> cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
>
>
> Characteristics of this binary (from libperl):
> Compile-time options: USE_64_BIT_INT USE_64_BIT_ALL USE_LARGE_FILES
> Built under linux
> Compiled at Dec 16 2004 22:56:14
> @INC:
> /usr/local/lib/perl5/5.8.6/x86_64-linux
> /usr/local/lib/perl5/5.8.6
> /usr/local/lib/perl5/site_perl/5.8.6/x86_64-linux
> /usr/local/lib/perl5/site_perl/5.8.6
> /usr/local/lib/perl5/site_perl
> .
>
> Any thoughts?
>
> Thanks,
>
> Matthew
>
>
>
--
Report problems: 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: compile problems
Posted by Stas Bekman <st...@stason.org>.
Matthew Berk wrote:
> Apologies if I'm posting in the wrong place, but here goes:
>
> AMD Opteron, Suse 9.1, perl 5.8.6, Apache 2.0.52, mod_perl 1.99_17
>
> Apache compiles fine. When compiling mod_perl, I execute
> "/usr/local/bin/perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs"
> and then make, and get:
>
> /usr/lib64/gcc-lib/x86_64-suse-linux/3.3.3/../../../../x86_64-suse-
> linux/bin/ld: /usr/local/lib/perl5/5.8.6/x86_64-linux/auto/DynaLoader/
> DynaLoader.a(DynaLoader.o): relocation R_X86_64_32 can not be used when
> making a shared object; recompile with -fPIC
> /usr/local/lib/perl5/5.8.6/x86_64-linux/auto/DynaLoader/DynaLoader.a:
> could not read symbols: Bad value
> collect2: ld returned 1 exit status
You mean, it fails to load Dynaloader? what was the last console before
this error?
Can you compile any other CPAN module that has XS code included? Looks
like it could be a broken perl.
--
__________________________________________________________________
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
--
Report problems: 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
compile problems
Posted by Matthew Berk <ma...@local-i.com>.
Apologies if I'm posting in the wrong place, but here goes:
AMD Opteron, Suse 9.1, perl 5.8.6, Apache 2.0.52, mod_perl 1.99_17
Apache compiles fine. When compiling mod_perl, I execute
"/usr/local/bin/perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs"
and then make, and get:
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.3/../../../../x86_64-suse-
linux/bin/ld:
/usr/local/lib/perl5/5.8.6/x86_64-linux/auto/DynaLoader/
DynaLoader.a(DynaLoader.o): relocation R_X86_64_32 can not be used when
making a shared object; recompile with -fPIC
/usr/local/lib/perl5/5.8.6/x86_64-linux/auto/DynaLoader/DynaLoader.a:
could not read symbols: Bad value
collect2: ld returned 1 exit status
A perl -V reveals:
Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
Platform:
osname=linux, osvers=2.6.5-7.95-smp, archname=x86_64-linux
uname='linux local03 2.6.5-7.95-smp #1 smp thu jul 1 15:23:45 utc
2004 x86_64 x86_64 x86_64 gnulinux '
config_args='-des -Dcccdlflags=-fPIC'
hint=previous, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=define uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-fno-strict-aliasing -pipe -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-fno-strict-aliasing -pipe -I/usr/local/include
-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -pipe -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
ccversion='', gccversion='3.3.3 (SuSE Linux)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.3.3'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: USE_64_BIT_INT USE_64_BIT_ALL USE_LARGE_FILES
Built under linux
Compiled at Dec 16 2004 22:56:14
@INC:
/usr/local/lib/perl5/5.8.6/x86_64-linux
/usr/local/lib/perl5/5.8.6
/usr/local/lib/perl5/site_perl/5.8.6/x86_64-linux
/usr/local/lib/perl5/site_perl/5.8.6
/usr/local/lib/perl5/site_perl
.
Any thoughts?
Thanks,
Matthew
--
Report problems: 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: [mp2] how to redirect POST data
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Beberle <be...@yahoo.com> writes:
> Ok, I'm getting closer but still not there yet. I've
> added a filter like so:
[...]
> I've been able to successfully capture the POST data
> without removing it from the chain. Problem is, it's
> too late. From what I've been able to gather from
> printing to the error log, the chain looks like this:
>
> PerlTransHandler --> PerlAccessHandler --> PerlHandler
> --> PerlInputFilterHandler
>
> I thought the filter was accessed before the
> response-handler.
Request filters aren't normally inserted into
the filter chain until the response-handler is
ready to run. mod_apreq is an exception, and it's
quite tricky to pull this off without breaking
lots of other things.
> What am I doing wrong?
What you're trying to do isn't a simple thing,
even if you're familiar with apache2's innards.
The input filter system wasn't really designed
to encourage people to do what you're doing.
So, have you tried using Apache::Request yet?
--
Joe Schaefer
--
Report problems: 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: [mp2] how to redirect POST data
Posted by Beberle <be...@yahoo.com>.
--- Joe Schaefer <jo...@sunstarsys.com> wrote:
> Beberle <be...@yahoo.com> writes:
>
> > Right, that's exactly the problem I'm trying to
> work
> > around. Once I've read the POST data, is there
> some
> > way to re-POST it?
>
> Not sure this is addressing your particular problem,
> but
> let me try to explain how Apache::Request tries to
> resolve
> this sort of thing in mp2.
>
> apache 2.x has filters, which can be plugged into
> the I/O
> chain just about anywhere. So if you think of the
> HTTP
> request as a pipeline between the user-agent and
> apache's
> response-handler
>
> [user-agent] -> [intermediate web proxies] ->
> [apache server] ->
>
> [connection filters] -> [protocol filters] ->
> [request filters] ->
>
> ^
> [response-handler]
Ok, I'm getting closer but still not there yet. I've
added a filter like so:
PerlInputFilterHandler Apache::RedirectPost
Its purpose is to grep the POST data for certain key
value pairs and if it matches, set some flag (cookie
or header). Then a handler down the chain can, in
theory, take some action based on this flag.
I also have these declarations:
PerlAccessHandler Apache::GateKeeper
PerlTransHandler Apache::DefaultTrans
PerlHandler Apache::Content
I've been able to successfully capture the POST data
without removing it from the chain. Problem is, it's
too late. From what I've been able to gather from
printing to the error log, the chain looks like this:
PerlTransHandler --> PerlAccessHandler --> PerlHandler
--> PerlInputFilterHandler
I thought the filter was accessed before the
response-handler. What am I doing wrong?
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
--
Report problems: 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: [mp2] how to redirect POST data
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Beberle <be...@yahoo.com> writes:
> Right, that's exactly the problem I'm trying to work
> around. Once I've read the POST data, is there some
> way to re-POST it?
Not sure this is addressing your particular problem, but
let me try to explain how Apache::Request tries to resolve
this sort of thing in mp2.
apache 2.x has filters, which can be plugged into the I/O
chain just about anywhere. So if you think of the HTTP
request as a pipeline between the user-agent and apache's
response-handler
[user-agent] -> [intermediate web proxies] -> [apache server] ->
[connection filters] -> [protocol filters] -> [request filters] ->
^
[response-handler] ^
^
(mod_apreq)
mod_apreq is a request filter which gets inserted into the
pipeline whenever someone makes a certain libapreq2 library
function call. In the mp2 case, that happens whenever
someone invokes Apache::Request::new.
Through mod_apreq, libapreq2 is able to parse the POST data
without removing the data from the pipeline. If it needs to,
mod_apreq will drive the pipeline to pull more data through,
but the data will remain in the pipeline for later filters/handlers
to see. It's designed this way to allow Apache::Request to be
usable in any pre-response-handler phase without losing the
POST data.
--
Joe Schaefer
--
Report problems: 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: [mp2] how to redirect POST data
Posted by Beberle <be...@yahoo.com>.
--- Tom Schindl <to...@gmx.at> wrote:
> Beberle wrote:
> > Hi,
> >
> > I found a similar question posted in the
> newsgroups
> > but no one seemed to have a solution. Here's what
> I'm
> > trying to do. I have a web page that does a POST
> to a
> > remote server. Basiscally, I'm trying to read the
> > post data and if it matches a regex, I want to
> > redirect it. Otherwise, I want to let the POST
> > continue normally (submitting to the remote
> server).
> >
> > At the PerlTransHandler stage, I have a handler
> that
> > reads the post data like so:
> >
> > my $method = $r->method();
> > if ($method =~ /post/i) {
> > my $content;
> > $r->read($content,
> > $r->headers_in->{'content-length'});
> > if ($content =~ /some_regex/){
> > # redirect
> > } else {
> > # continue with post
> > return OK;
> > }
> > }
> >
> > I can capture the POST data and redirect the user
> just
> > fine. The problem occurs with the submitted forms
> that
> > don't match the regex. If I just return OK, the
> > browser hangs (because the POST data has been
> reset?).
> > I'll admit I'm a bit confused as to what's
> actually
> > going on here (still new to mod_perl). I read
> you're
> > not supposed to parse the form data except at the
> > ContentHandler step, but since the form is
> submitting
> > to a remote host, I can't really do that.
> >
>
> Not 100% sure what you are telling me here but why
> not simply use
> Apache::Request->instance($r).
>
> The problem with POSTED data is that you can not
> read them more than
> once you can think of it like STDIN when read once
> you can not go back
> and read it once more.
Right, that's exactly the problem I'm trying to work
around. Once I've read the POST data, is there some
way to re-POST it?
__________________________________
Do you Yahoo!?
Jazz up your holiday email with celebrity designs. Learn more.
http://celebrity.mail.yahoo.com
--
Report problems: 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: [mp2] how to redirect POST data
Posted by Tom Schindl <to...@gmx.at>.
Beberle wrote:
> Hi,
>
> I found a similar question posted in the newsgroups
> but no one seemed to have a solution. Here's what I'm
> trying to do. I have a web page that does a POST to a
> remote server. Basiscally, I'm trying to read the
> post data and if it matches a regex, I want to
> redirect it. Otherwise, I want to let the POST
> continue normally (submitting to the remote server).
>
> At the PerlTransHandler stage, I have a handler that
> reads the post data like so:
>
> my $method = $r->method();
> if ($method =~ /post/i) {
> my $content;
> $r->read($content,
> $r->headers_in->{'content-length'});
> if ($content =~ /some_regex/){
> # redirect
> } else {
> # continue with post
> return OK;
> }
> }
>
> I can capture the POST data and redirect the user just
> fine. The problem occurs with the submitted forms that
> don't match the regex. If I just return OK, the
> browser hangs (because the POST data has been reset?).
> I'll admit I'm a bit confused as to what's actually
> going on here (still new to mod_perl). I read you're
> not supposed to parse the form data except at the
> ContentHandler step, but since the form is submitting
> to a remote host, I can't really do that.
>
Not 100% sure what you are telling me here but why not simply use
Apache::Request->instance($r).
The problem with POSTED data is that you can not read them more than
once you can think of it like STDIN when read once you can not go back
and read it once more.
> Any ideaas?
In mp2 you could also use an input-filter for this purpose.
>
> Thanks,
> Bill
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
--
Report problems: 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