Newer Older
53 lines | 1.43kb
cleanup
Yuki Kimoto authored on 2013-10-02
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
Yuki Kimoto authored on 2016-03-25
8
    $self->reply->exception('Invalid URL');
cleanup
Yuki Kimoto authored on 2013-10-02
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
Yuki Kimoto authored on 2013-10-08
21
  elsif ($path eq 'objects/info/packs') {
cleanup
Yuki Kimoto authored on 2013-10-02
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
Yuki Kimoto authored on 2013-10-08
33
  
cleanup
Yuki Kimoto authored on 2016-04-16
34
  my $rep_info = app->rep_info($user, $project);
35
  my $rep_git_dir = $rep_info->{git_dir};
36
  my $file = "$rep_git_dir/$path";
add test HEAD
Yuki Kimoto authored on 2013-10-08
37
  if (-f $file) {
38
    my $asset = Mojo::Asset::File->new(path => $file);
39
    my $content = $asset->slurp;
40
    $content = '' unless defined $content;
fix and add loose object tes...
Yuki Kimoto authored on 2013-10-08
41
    $self->res->headers->content_type($content_type);
42
    $self->res->headers->content_length(length $content);
43
    $self->res->body($content);
44
    $self->res->code(200);
45
    $self->rendered;
46
    return;
47
  }
48
  else {
49
    $self->res->code(404);
50
    $self->rendered;
51
    return;
52
  }
cleanup
Yuki Kimoto authored on 2013-10-02
53
%>