cleanup
|
1 |
<% |
2 |
my $path = param('Path'); |
|
3 |
my $user = param('user'); |
|
4 |
my $project = param('project'); |
|
5 | ||
6 |
# Protect directory traversal |
|
7 |
if ($path =~ m#\.\.#) { |
|
do success xt tests
|
8 |
$self->reply->exception('Invalid URL'); |
cleanup
|
9 |
return; |
10 |
} |
|
11 | ||
12 |
# Content type |
|
13 |
my $content_type; |
|
14 |
if ($path eq 'HEAD' |
|
15 |
|| $path eq 'objects/info/alternates' |
|
16 |
|| $path eq 'objects/info/http-alternates' |
|
17 |
) |
|
18 |
{ |
|
19 |
$content_type = 'text/plain'; |
|
20 |
} |
|
add test HEAD
|
21 |
elsif ($path eq 'objects/info/packs') { |
cleanup
|
22 |
$content_type = 'text/plain; charset=UTF-8'; |
23 |
} |
|
24 |
elsif ($path =~ m#^objects/[0-9a-f]{2}/[0-9a-f]{38}$#) { |
|
25 |
$content_type = 'application/x-git-loose-object'; |
|
26 |
} |
|
27 |
elsif ($path =~ m#^objects/pack/pack-[0-9a-f]{40}\.pack$#) { |
|
28 |
$content_type = 'application/x-git-packed-objects'; |
|
29 |
} |
|
30 |
elsif ($path =~ m#^objects/pack/pack-[0-9a-f]{40}\.idx$#) { |
|
31 |
$content_type = 'application/x-git-packed-objects-toc'; |
|
32 |
} |
|
add test HEAD
|
33 |
|
revert encoding support
|
34 |
my $rep_home = app->git->rep_home; |
add test HEAD
|
35 |
my $file = "$rep_home/$user/$project.git/$path"; |
36 |
if (-f $file) { |
|
37 |
my $asset = Mojo::Asset::File->new(path => $file); |
|
38 |
my $content = $asset->slurp; |
|
39 |
$content = '' unless defined $content; |
|
fix and add loose object tes...
|
40 |
$self->res->headers->content_type($content_type); |
41 |
$self->res->headers->content_length(length $content); |
|
42 |
$self->res->body($content); |
|
43 |
$self->res->code(200); |
|
44 |
$self->rendered; |
|
45 |
return; |
|
46 |
} |
|
47 |
else { |
|
48 |
$self->res->code(404); |
|
49 |
$self->rendered; |
|
50 |
return; |
|
51 |
} |
|
cleanup
|
52 |
%> |