Thread: [pastebot-cvs] pastebot/Server Web.pm,1.14,1.15
Status: Beta
Brought to you by:
rcaputo
From: <rc...@us...> - 2003-10-30 17:38:58
|
Update of /cvsroot/pastebot/pastebot/Server In directory sc8-pr-cvs1:/tmp/cvs-serv4988/Server Modified Files: Web.pm Log Message: Allow the bot itself to serve small files. Alter Yaakov's new templates so the image links point into the bot. Now they're totally self-contained. Index: Web.pm =================================================================== RCS file: /cvsroot/pastebot/pastebot/Server/Web.pm,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Web.pm 6 Jul 2003 17:49:09 -0000 1.14 --- Web.pm 30 Oct 2003 17:38:55 -0000 1.15 *************** *** 137,140 **** --- 137,189 ---- } + ### Fetch some kind of data. + + if ($url =~ m{^/(data/.+?)\s*$}) { + # TODO - Better path support. + my $filename = $1; + $filename =~ s/\.\.\/\///g; + $filename =~ s/\/+/\//g; + + my ($code, $type, $content); + + if (-e $filename) { + if (open(FILE, "<$filename")) { + $code = 200; + local $/; + $content = <FILE>; + close FILE; + + # TODO - Better type support. + if ($filename =~ /\.(gif|jpe?g|png)$/i) { + $type = lc($1); + $type = "jpeg" if $type eq "jpg"; + $type = "image/$1"; + } + } + else { + $code = 500; + $type = "text/html"; + $content = ( + "<html><head><title>File Error</title></head>" . + "<body>Error opening $filename: $!</body></html>" + ); + } + } + else { + $code = 404; + $type = "text/html"; + $content = ( + "<html><head><title>404 File Not Found</title></head>" . + "<body>File $filename does not exist.</body></html>" + ); + } + + my $response = HTTP::Response->new($code); + $response->push_header('Content-type', $type); + $response->content($content); + $heap->{wheel}->put( $response ); + return; + } + ### Store paste. |