Ronnie Doorzon has asked for the wisdom of the Perl Monks concerning the following question:

I'm getting messages on a apache web server( proxy) to the same url but they need to go to different nodes. Is it possible to write a perl script that forwards it to the right node based on the content of the message? So far I created a Location in apache and created a first.pm. This first.pm can read the body and can decide where it should go. I tried redirecting, this works but the body(data) of the message is lost. Instead of redirecting the messaged should be "forwarded" (proxy) to a new url. Message on http://proxy/first body contains "first" -> to node 1 body contains "second" -> to node 2 Can this be done and if yes any hint in the right direction? Cheers.

Replies are listed 'Best First'.
Re: proxy on XML content
by derby (Abbot) on Aug 08, 2009 at 00:24 UTC

    If you need to inspect the POST data in order to determine where to redirect, your best bet is a mod_perl handler that converts the POST request to a GET request and then redirects. Practical Modperl has an example. The only caveat I can think of would be there's a limit on the maximum size a GET request can be.

    -derby
Re: proxy on XML content
by ig (Vicar) on Aug 08, 2009 at 08:56 UTC

    If node 1 and node 2 are on the same server, rather than redirecting the browser, you might call the functions that would serve those URLs directly allowing them to return their results in response to the original request.

    If node 1 or node 2 are on some other server, you could have your existing program (first.pm) submit the query and return the result to the browser. You could use LWP for this, or any other module that provides HTTP client functions.