-
- my $f = $git->{git_dir} . '/' . $path;
- return r(404) unless -f $f && -r _; # just in case it's a FIFO :P
- my $size = -s _;
-
- # TODO: If-Modified-Since and Last-Modified?
- open my $in, '<', $f or return r(404);
- my $len = $size;
- my $code = 200;
- push @h, 'Content-Type', $type;
- if (($env->{HTTP_RANGE} || '') =~ /\bbytes=(\d*)-(\d*)\z/) {
- ($code, $len) = prepare_range($env, $in, \@h, $1, $2, $size);
- if ($code == 416) {
- push @h, 'Content-Range', "bytes */$size";
- return [ 416, \@h, [] ];
- }
- }
- push @h, 'Content-Length', $len;
- my $n = 65536;
- [ $code, \@h, Plack::Util::inline_object(close => sub { close $in },
- getline => sub {
- return if $len == 0;
- $n = $len if $len < $n;
- my $r = sysread($in, my $buf, $n);
- if (!defined $r) {
- err($env, "$f read error: $!");
- } elsif ($r <= 0) {
- err($env, "$f EOF with $len bytes left");
- } else {
- $len -= $r;
- $n = 8192;
- return $buf;
- }
- drop_client($env);
- return;
- })]
+ $path = "$git->{git_dir}/$path";
+ PublicInbox::WwwStatic::response($env, $h, $path, $type);