- my $f = "$git->{git_dir}/$path";
- return r(404) unless -f $f && -r _;
- my @st = stat(_);
- my $size = $st[7];
-
- # TODO: If-Modified-Since and Last-Modified
- open my $in, '<', $f or return r(404);
- my $code = 200;
- my $len = $size;
- my @h;
-
- my $env = $cgi->{env};
- my $range = $env->{HTTP_RANGE};
- if (defined $range && $range =~ /\bbytes=(\d*)-(\d*)\z/) {
- ($code, $len) = prepare_range($cgi, $in, \@h, $1, $2, $size);
- if ($code == 416) {
- push @h, 'Content-Range', "bytes */$size";
- return [ 416, \@h, [] ];
- }
- }
-
- push @h, 'Content-Type', $type, 'Content-Length', $len;
- sub {
- my ($res) = @_; # Plack callback
- my $fh = $res->([ $code, \@h ]);
- my $buf;
- my $n = 8192;
- while ($len > 0) {
- $n = $len if $len < $n;
- my $r = read($in, $buf, $n);
- last if (!defined($r) || $r <= 0);
- $len -= $r;
- $fh->write($buf);
- }
- $fh->close;
- }
+ $path = "$git->{git_dir}/$path";
+ PublicInbox::WwwStatic::response($env, $h, $path, $type);