/[pxelator]/lib/PXElator/httpd.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/httpd.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 64 by dpavlin, Thu Jul 30 16:26:54 2009 UTC revision 65 by dpavlin, Thu Jul 30 17:07:48 2009 UTC
# Line 30  use html; Line 30  use html;
30  sub static {  sub static {
31          my ($client,$path) = @_;          my ($client,$path) = @_;
32    
33          $path = "tftp/$path";          my $full = "$server::base_dir/tftp/$path";
34    
35          if ( ! -e $path ||  -d $path ) {          return if ! -f $full;
                 print $client "HTTP/1.0 404 $path not found\r\n";  
                 return;  
         }  
36    
37          my $type = 'text/plain';          my $type = 'application/octet-stream';
38          $type = 'text/html' if $path =~ m{\.htm};          $type = 'text/html' if $path =~ m{\.htm};
39          $type = 'application/javascript' if $path =~ m{\.js};          $type = 'application/javascript' if $path =~ m{\.js};
40            $type = 'text/plain' if $path =~ m{\.txt};
41    
42            my $size = -s $full || return;
43    
44            print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: $size\r\nConnection: close\r\n\r\n";
45    
46          print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: ", -s $path,"\r\n\r\n";          open(my $fh, $full);
47          open(my $html, $path);          print "static $path $type $size\n";
48          while(<$html>) {  
49                  print $client $_;          my $block = 8192;
50            my $buff;
51            my $pos = 0;
52    
53            while( my $len = read $fh, $buff, $block ) {
54                    print $client $buff;
55                    $pos += $len;
56                    printf "%s %d/%d %.2f%%\r", $path, $pos, $size, $pos * 100 / $size;
57          }          }
58          close($html);          close($fh);
59            close($client);
60    
61            print "$path $pos == $size OK\n";
62    
63          return $path;          return $path;
64  }  }

Legend:
Removed from v.64  
changed lines
  Added in v.65

  ViewVC Help
Powered by ViewVC 1.1.26