Showing 3 changed files with 25 additions and 9 deletions
+7 -4
templates/smart-http/info-refs.html.ep
... ...
@@ -65,11 +65,14 @@
65 65
     close $fh
66 66
       or die "Can't close pipe for @cmd:$!";
67 67
     
68
+    my $content_type = 'text/plain; charset=UTF-8';
68 69
     my $rep_home = app->git->rep_home;
69
-    my $file = Mojo::Asset::File->new(path => "$rep_home/$user/$project.git/info/refs");
70
-    my $content = $file->slurp;
71
-    if (defined $content) {
72
-      $self->res->headers->content_type('text/plain; charset=UTF-8');
70
+    my $file = "$rep_home/$user/$project.git/info/refs";
71
+    if (-f $file) {
72
+      my $asset = Mojo::Asset::File->new(path => $file);
73
+      my $content = $asset->slurp;
74
+      $content = '' unless defined $content;
75
+      $self->res->headers->content_type($content_type);
73 76
       $self->res->headers->content_length(length $content);
74 77
       $self->res->body($content);
75 78
       $self->res->code(200);
+7 -5
templates/smart-http/static.html.ep
... ...
@@ -18,7 +18,7 @@
18 18
   {
19 19
     $content_type = 'text/plain';
20 20
   }
21
-  elsif ($path eq '/objects/info/packs') {
21
+  elsif ($path eq 'objects/info/packs') {
22 22
     $content_type = 'text/plain; charset=UTF-8';
23 23
   }
24 24
   elsif ($path =~ m#^objects/[0-9a-f]{2}/[0-9a-f]{38}$#) {
... ...
@@ -30,11 +30,13 @@
30 30
   elsif ($path =~ m#^objects/pack/pack-[0-9a-f]{40}\.idx$#) {
31 31
     $content_type = 'application/x-git-packed-objects-toc';
32 32
   }
33
-
33
+  
34 34
   my $rep_home = app->git->rep_home;
35
-  my $file = Mojo::Asset::File->new(path => "$rep_home/$user/$project.git/info/refs");
36
-  my $content = $file->slurp;
37
-  if (defined $content) {
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;
38 40
     $self->res->headers->content_type($content_type);
39 41
     $self->res->headers->content_length(length $content);
40 42
     $self->res->body($content);
+11
xt/smart_http.t
... ...
@@ -70,5 +70,16 @@ note 'Smart HTTP';
70 70
   $t->status_is(200);
71 71
   $t->content_type_is('application/x-git-loose-object');
72 72
 
73
+  # /info/pack
74
+  $t->get_ok("/kimoto/t1.git/objects/info/packs");
75
+  $t->status_is(200);
76
+  $t->content_type_is('text/plain; charset=UTF-8');
73 77
 
78
+  # /HEAD
79
+  $t->get_ok("/kimoto/t1.git/HEAD");
80
+  $t->status_is(200);
81
+  $t->content_type_is('text/plain');
82
+  $t->content_like(qr#ref: refs/heads/master#);
83
+  
84
+  
74 85
 }