Skip to content

Commit

Permalink
add start http static file dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-kimoto committed Oct 1, 2013
1 parent 21eecab commit ae911c6
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions lib/Gitprep.pm
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,47 @@ sub startup {

# $r->post('/git-upload-pack');
# $r->post('/git-receive-pack');
# $r->get('/HEAD');
# $r->get('/objects/info/alternates');
# $r->get('/objects/info/http-alternates');
# $r->get('/objects/info/packs');
# $r->get('/objects/[0-9a-f]{2}/[0-9a-f]{38}');
# $r->get('/objects/pack/pack-[0-9a-f]{40}\.pack');
# $r->get('/objects/pack/pack-[0-9a-f]{40}\.idx');

$r->get('/(*Path)')->to(cb => sub {
my $self = shift;

my $path = $self->param('Path');
my $user = $self->param('user');
my $project = $self->param('project');

warn $self->dumper($path, $user, $project);

# Protect directory traversal
if ($path =~ m#\.\.#) {
$self->render_exception('Invalid URL');
return;
}

# Content type
my $content_type;
if ($path eq 'HEAD'
|| $path eq 'objects/info/alternates'
|| $path eq 'objects/info/http-alternates'
)
{
$content_type = 'text/plain';
}
elsif ($path eq '/objects/info/packs') {
$content_type = 'text/plain; charset=UTF-8';
}
elsif ($path =~ m#^objects/[0-9a-f]{2}/[0-9a-f]{38}$#) {
$content_type = 'application/x-git-loose-object';
}
elsif ($path =~ m#^objects/pack/pack-[0-9a-f]{40}\.pack$#) {
$content_type = 'application/x-git-packed-objects';
}
elsif ($path =~ m#^objects/pack/pack-[0-9a-f]{40}\.idx$#) {
$content_type = 'application/x-git-packed-objects-toc';
}

$self->res->headers->content_type($content_type) if $content_type;
$self->render_static("../data/rep/$user/$project.git/$path");
});
}

# Project
Expand Down

0 comments on commit ae911c6

Please sign in to comment.