Saving files in Perl

P

PuZzLeD

Hi,
I have a problem here. I am supposed to be saving downloaded web pages
on to a a local cache. I have written a forking proxy server that
reads the request frm the browser and passes the request to the
Internet Gateway and then gets back the data from the internet gateway
and then passes it on to the browser. I need to save the files that
are associated with each request into a local cache. I have attached
the server code below...


server_listenport = IO::Socket::INET->new(
LocalPort => $server_listenport,
Listen => $listen_queuesize)
or die "couldnt be a tcp server on port $server_listenport:
$@\n";


while($browser_request=$server_listenport->accept())
{
if (fork == 0)
{
#child
print " \n\nUsing Child Proceess...\n";
close ($server_listenport);
sysread($browser_request,$req_webpage,2048);
$date_stamp= `date`;
$internet_gateway =IO::Socket::INET->new(
PeerPort=>$IGway_listenport,
PeerAddr=>$IGway_hostname) or die " cannot
connect to gateway";

syswrite($internet_gateway,$req_webpage);

while(sysread($internet_gateway, $recv_webpage, 20480) > 0)
{
syswrite($browser_request,$recv_webpage);
}
print "\n\n\tWeb page is now downloaded!!\n\n";
close($internet_gateway);

exit;
}
}
else
{
#parent
print " \n\nUsing Parent Process...\n";
close($browser_request);
}
} #end of while


Can some1 help me ?
 
J

Joe Smith

PuZzLeD wrote:

I have a problem here.

You'll have better luck getting answers in comp.lang.perl.misc instead of here.
I need to save the files that
are associated with each request into a local cache.

There are plenty of caching proxy servers out there, why re-invent the wheel?

If you feel you must, you will have to invent your own algorithm for
converting "GET http://www.example.com/big/long/URL http/1.0" to a file name
and you _must_ honor If-Modified-Since: and Expires: headers.
$date_stamp= `date`;

$date_stamp = localtime . "\n";

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top