--- lib/PXElator/httpd.pm 2009/07/30 16:26:54 64 +++ lib/PXElator/httpd.pm 2009/07/30 17:07:48 65 @@ -30,23 +30,35 @@ sub static { my ($client,$path) = @_; - $path = "tftp/$path"; + my $full = "$server::base_dir/tftp/$path"; - if ( ! -e $path || -d $path ) { - print $client "HTTP/1.0 404 $path not found\r\n"; - return; - } + return if ! -f $full; - my $type = 'text/plain'; + my $type = 'application/octet-stream'; $type = 'text/html' if $path =~ m{\.htm}; $type = 'application/javascript' if $path =~ m{\.js}; + $type = 'text/plain' if $path =~ m{\.txt}; + + my $size = -s $full || return; + + print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: $size\r\nConnection: close\r\n\r\n"; - print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: ", -s $path,"\r\n\r\n"; - open(my $html, $path); - while(<$html>) { - print $client $_; + open(my $fh, $full); + print "static $path $type $size\n"; + + my $block = 8192; + my $buff; + my $pos = 0; + + while( my $len = read $fh, $buff, $block ) { + print $client $buff; + $pos += $len; + printf "%s %d/%d %.2f%%\r", $path, $pos, $size, $pos * 100 / $size; } - close($html); + close($fh); + close($client); + + print "$path $pos == $size OK\n"; return $path; }