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

Before I dive into code, I need to explain our architecture. Three machines are involved: the clients are at a remote third-company site, the web-server is located in a DMZ, and we have a pubs server located inside our network that generates a PDF from xml that I send, after appliying business rules, etc.

Currently, I SFTP the file from the web server to the pubs server and redirect the client as such:

my $redirectURL = 'http://'. $destination_server . '/cgi-bin/pubtools +/ebom.' . $extension . '?XML=' . $randomName; + ## copy our XML to the correct location/filename $logger->info("Report requested, FTP $localfile to $destination_server +"); my $ftp = Net::SFTP->new($destination_server, Debug=>0); $ftp->login($login, $pass) or $logger->error("Could not connect to Pub +s Server"); $ftp->cwd($destination_path) or $logger->error("Could not change direc +tories on Pubs Server"); $ftp->put($localfile, $randomName) or $logger->error("Could not transf +er file to Pubs Server"); $ftp->site('chmod','0666',$randomName) or $logger->error("Could not ch +mod remote file"); $ftp->quit; + ## Now we redirect them to the generated PDF + $logger->info("Redirecting to $redirectURL"); + print $cgi->redirect(-target => 'ResultWindow', -expires => 'now', -ur +i=>$redirectURL);
Now, for security reasons, I can no longer let the client communicate directly to the pubs server, so everything has to go through the web server in the DMZ.

So instead of redirecting, I need to call this URL directly from the server and stream the data back to the browser. Any idea of how to do this? Thanks.

Replies are listed 'Best First'.
Re: Streaming data through web server to browser with CGI
by moritz (Cardinal) on Aug 15, 2007 at 20:33 UTC
    That's called a proxy, and most webservers can do that for you - no need to implement it in perl ;-)
      For stupid management reasons it looks like using Apache's proxy functionality is a no go. I have to feed it through the HTTP connection I already have.
Re: Streaming data through web server to browser with CGI
by rashley (Scribe) on Aug 16, 2007 at 15:29 UTC
    A monk directed me to LWP::UserAgent. So here's where I am.
    my $ua = LWP::UserAgent->new; $ua->timeout(30); my $response = $ua->get($redirectURL); if ($response->is_success) { $logger->info("Grabbing data and passing it to browser."); print $response->content; # or whatever $logger->info($response->content); } else { $logger->info("Didn't get the data."); die $response->status_line; }
    I'm seeing the "Grabbing data and passing it to browser." message, and the data in the browser looks like the PDF data I want, but I'm getting an Internal Server Error on the browser.

    Thoughts?

      What's the corresponding message in your webserver's error.log?
        "Premature end of script headers"